createContentClient()
createContentClient(options)
Creates an HTTP client bound to a server handler endpoint. The returned type is the base client plus whatever methods client plugins contribute.
Parameters:
options?: aContentClientOptionsobject (plus an optionalpluginsarray). See Options.
Returns: ContentClient & <plugin methods>, the base client whose methods are always present, extended with any methods that client plugins contribute.
import { createContentClient } from 'comark-content/client'
export const content = createContentClient({ basePath: '/api/content' })Options
| Option | Type | Default | Description |
|---|---|---|---|
baseURL | string | '' | Origin of the server handler (empty for same-origin). |
basePath | string | '/api/content' | Path where content.handler() is mounted. |
fetch | ContentFetch | global fetch | Fetch implementation used for every request. |
plugins | ContentClientPlugin[] | [] | Client plugins to install at construction. |
baseURL
The origin the client prefixes onto requests. Leave it empty for a same-origin app; set it (e.g. https://docs.example.com) to read from a Content hosted elsewhere.
basePath
The path the server handler is mounted at. Must match the basePath passed to comarkContent. Defaults to /api/content.
fetch
A custom ContentFetch ((url, options?) => Promise<T>). Defaults to the global fetch. Pass Nuxt's $fetch, an authenticated wrapper, or a mock in tests.
plugins
Client plugins built with defineContentClientPlugin. They add methods to the returned client, mirroring the Content instance plugin they pair with.
Usage
import { createContentClient } from 'comark-content/client'
export const content = createContentClient({ basePath: '/api/content' })