Content Client SDK
The Content Client (ContentClient from @uniformdev/canvas) provides programmatic access to headless content entries stored in Uniform. Use it for server-side data fetching, search indexing, custom API routes, or any scenario where you need to query content outside of the standard composition rendering pipeline.
note
Within the App Router SDK's composition rendering flow, content is resolved automatically. The Content Client is for use cases where you need to access content directly -- such as building sitemaps, search indexes, custom API endpoints, or fetching content that isn't part of a composition.
Installation#
The Content Client is part of the @uniformdev/canvas package:
Initializing the client#
Standalone usage#
When using the Content Client outside the App Router SDK (e.g., in scripts or API routes):
Within the App Router SDK#
When using the App Router SDK, you can use the pre-configured getCanvasClient for composition access:
Fetching entries#
Get entries by content type#
Pagination#
Search and filtering#
The Content Client supports advanced filtering using a structured query syntax. Filters are passed as key-value pairs where the key includes the field path and operator.
Filter syntax#
field: The field to filter by. Usetypefor content type,fields.<fieldName>for custom fields, or system properties likename,slug,_created,_modified.operator: The comparison operator.value: The literal value to compare against.
Example: filter by content type and field value#
Available operators#
String fields (name, slug, text fields)#
| Operator | Description |
|---|---|
eq | Equals |
neq | Not equal |
match | Contains substring |
starts | Starts with |
in | Matches any value in a comma-separated list |
nin | Does not match any value in a list |
Numeric fields#
| Operator | Description |
|---|---|
eq | Equal to |
neq | Not equal to |
gt | Greater than |
gte | Greater than or equal to |
lt | Less than |
lte | Less than or equal to |
Date fields (_created, _modified)#
| Operator | Description |
|---|---|
eq | Equals a specific date |
gt | After a specific date |
gte | On or after |
lt | Before a specific date |
lte | On or before |
Optional fields (locale, pattern ID)#
| Operator | Description |
|---|---|
eq | Equals |
neq | Not equal |
def | Field is defined (has a value) |
Filtering reference fields#
For reference fields, you can filter by the referenced entry's properties:
Filterable reference properties: name, slug, uiStatus, type.
Combining multiple filters#
Combine multiple filters to narrow results:
Filtering compositions#
The Canvas Client supports the same filtering syntax for compositions, but uses parameters instead of fields:
Building a search index#
A common use case for the Content Client is building a search index. Here is a pattern that retrieves all compositions via the project map and extracts text content for indexing:
note
For large sites, consider running index rebuilds outside the Next.js build process to avoid build timeout limits. You can trigger rebuilds via a webhook when content is published.
Limitations#
- Nested object search is not supported: You cannot filter by a parameter of a component within a composition, or by a field of a block within an entry.
- Faceting is available for numeric and short text fields, but requires specifying a single content type filter.
Import reference#
| Export | Package | Description |
|---|---|---|
ContentClient | @uniformdev/canvas | Client for fetching content entries |
CanvasClient | @uniformdev/canvas | Client for fetching compositions |
RouteClient | @uniformdev/canvas | Client for route resolution |
getCanvasClient | @uniformdev/next-app-router | Pre-configured canvas client (server-only) |
getRouteClient | @uniformdev/next-app-router | Pre-configured route client (server-only) |