createContentClient()

Creates a browser-safe HTTP client bound to a server handler endpoint.

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:

Returns: ContentClient & <plugin methods>, the base client whose methods are always present, extended with any methods that client plugins contribute.

usage.ts
import { createContentClient } from 'comark-content/client'

export const content = createContentClient({ basePath: '/api/content' })

Options

OptionTypeDefaultDescription
baseURLstring''Origin of the server handler (empty for same-origin).
basePathstring'/api/content'Path where content.handler() is mounted.
fetchContentFetchglobal fetchFetch implementation used for every request.
pluginsContentClientPlugin[][]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

app/content.ts
import { createContentClient } from 'comark-content/client'

export const content = createContentClient({ basePath: '/api/content' })