API
The three ways to reach your content.
Tenon has one set of operations, with three ways to call them. They share the names, the options and the access rules.
| Way | Where it runs | Use it for |
|---|---|---|
| Local API | Your server code | Pages, hooks, tasks, scripts. No HTTP in between |
| Client | The browser, or another service | Islands, client components, admin pages, a frontend on another origin |
| HTTP routes | Anything that sends HTTP | Other languages, tools like n8n, curl |
// Server code: the local API
import cms from "../tenon.config";
const posts = await cms.find("posts", { limit: 3 });
// Browser code: the client
import { createClient } from "tenoncms/client";
const client = createClient();
const same = await client.find("posts", { limit: 3 });
# Anything else: the HTTP route
curl "https://example.com/_tenon/collections/posts?limit=3"
How they differ
- The imported
cmsskips the access rules. The client and the routes always apply them, for the user of the session or the API key. - The local API reads published content. The client and the routes read drafts only in preview.
- Some methods exist on one side only. See Methods only on the client.
Related resources
- Reading and Writing and drafts: guides with examples.
- HTTP API and client: the client in the browser and in other services.
- Errors and types: what a failed call throws.