Foundations
Installation
Install @uidu/client and configure tokens.
Install the packages
npm install @uidu/client
# or
yarn add @uidu/client
# or
pnpm add @uidu/clientIf you're using React, also install the bindings:
npm install @uidu/reactBoth packages publish "sideEffects": false and are fully tree-shakable — only the functions you import end up in your bundle.
Configure tokens
A site needs a public token (Workspace → Settings → Public tokens, safe in the browser) and, for anything that writes or reads private data, an API key (Workspace → Settings → API keys, server only). Authentication explains which to use where.
A typical .env:
UIDU_WORKSPACE=acme
UIDU_PUBLIC_TOKEN=pk_live_...
UIDU_API_KEY=sk_live_... # server only
UIDU_PROJECT_ID=Z2lkOi8v... # legacy Projects CMS onlyVerify the install
import { createClient } from '@uidu/client';
const client = createClient({
workspace: process.env.UIDU_WORKSPACE!,
publicToken: process.env.UIDU_PUBLIC_TOKEN!,
});
const ping = await fetch(client.endpoint).then((r) => r.status);
console.log(ping); // 200 if reachable, 401 if token is wrongThe endpoint resolves to https://{workspace}.uidu.org/graphql by default. Override with the endpoint option for local Rails dev (http://localhost:3000/graphql).
Continue with the quickstart.