Call Uniform APIs on the server

Developer preview

This feature is in developer preview. Use with caution as it may change unexpectedly. For more information, contact us.

Developer Preview

This page documents the developer preview of the SDK, version 20.81.1-alpha.25.sha-f076f9b857.

Task: get data from a Uniform API in a Server Component, a Route Handler or a Server Action, with the Next.js data cache.

The SDK has server-only clients that are configured for the Next.js data cache:

import { getCompositionDeliveryClient, getManifest, getManifestClient, getProjectMapClient, getRouteClient, } from "@uniformdev/next-app-router";
import { CANVAS_PUBLISHED_STATE } from "@uniformdev/canvas"; import { getCompositionDeliveryClient, getManifest, getProjectMapClient } from "@uniformdev/next-app-router"; // Get a composition by its ID const composition = await getCompositionDeliveryClient({ state: CANVAS_PUBLISHED_STATE }).get({ compositionId: "abc123", state: CANVAS_PUBLISHED_STATE, }); // Get the published Context manifest const manifest = await getManifest({ state: CANVAS_PUBLISHED_STATE }); // Get the project map nodes, with the Next.js default fetch cache const { nodes } = await getProjectMapClient({ cache: { type: "default" } }).getNodes({});

Each getter takes one of these options:

OptionCache
{ cache: { type: "force-cache" } }The fetch cache mode that you set. { type: "revalidate", interval: 60 } revalidates after 60 seconds.
{ state }no-cache for the draft and editor states, force-cache for published.
{ searchParams, draftModeEnabled }no-cache in draft mode, in visual editing and in development, else force-cache.

The route, composition and manifest clients add cache tags, so the webhook handler can revalidate them. The project map client adds no tags. These clients import server-only. You cannot use them in client components. For the methods, refer to Route Client and Project Map Client.

getCanvasClient is deprecated. Use getCompositionDeliveryClient.