---
title: "defineContentClientPlugin()"
description: "Author a client-side plugin that adds typed methods to the Content instance client."
canonical_url: "https://content.comark.dev/reference/plugins/define-content-client-plugin"
---
# defineContentClientPlugin()

> Author a client-side plugin that adds typed methods to the Content instance client.

## `defineContentClientPlugin(factory)`

Defines a client-side plugin. Same shape as [`defineContentPlugin`](https://content.comark.dev/reference/plugins/define-content-plugin), but `setup` receives the client (with its resolved `options`: `baseURL`, `basePath`, `fetch`) instead of the Content instance plugin context, and is synchronous.

**Parameters:**

- `factory`: `(options?: TOptions) => { setup: (client: ContentClientWithOptions) => TMethods | void }`.

**Returns:** a client plugin factory `(...args) => `[`ContentClientPlugin`](https://content.comark.dev/reference/types/plugins#contentclientplugin)`<TMethods>` to pass to [`createContentClient({ plugins })`](https://content.comark.dev/reference/client/create-content-client).

```ts [plugin.ts]
import { defineContentClientPlugin } from 'comark-content/client'

export default defineContentClientPlugin(() => ({
  setup(client) {
    return {
      searchSections: (q: string) =>
        client.options.fetch(`${client.options.basePath}/search-sections?q=${q}`, { responseType: 'json' }),
    }
  },
}))
```

Import client plugins from `comark-content/client`; import Content plugins from `comark-content`.

## Usage

Pair the client plugin with the [`defineContentPlugin`](https://content.comark.dev/reference/plugins/define-content-plugin) that registers the matching section, so the two halves live in one place:

```ts [search-client.ts]
import { defineContentClientPlugin } from 'comark-content/client'

export default defineContentClientPlugin(() => ({
  setup(client) {
    return {
      searchSections: (q: string) =>
        client.options.fetch(`${client.options.basePath}/search-sections?q=${q}`, { responseType: 'json' }),
    }
  },
}))
```

Register it with [`createContentClient({ plugins })`](https://content.comark.dev/reference/client/create-content-client) to add the method to the client.


## Sitemap

See the full [sitemap](https://content.comark.dev/sitemap.md) for all pages.
