Routes and access
Declare HTTP routes, set who may call them, and build responses.
Declaring routes
Use app.get, app.post, app.put, app.patch, app.delete or app.all with a path, optional metadata and one or more handlers.
- Paths look like
/tasksor/tasks/:id. A trailing*matches the rest of the path, read withc.req.param("*"). - Routes declared first win.
- Up to 100 routes per service.
Route metadata
| Field | Description |
|---|---|
name | Name used to call the route from an HTML page with think.call(name, args) and from MCP. Letters, digits and _ . : -; must be unique. |
description | What the route does. |
access | Who may call it: "space" (default), "user" or "public". See below. |
Access levels
| Value | Who can call the route |
|---|---|
space | People invited to the project, the project's thk_ API keys, and people who can open an HTML page of the project (through think.call). This is the default. |
user | Anyone signed in to OpenThink. |
public | Anyone, including callers who are not signed in. viewer is null. Use it for webhooks from Stripe or GitHub and for public forms. |
Read-only API keys can only call GET routes.
Middleware and errors
app.use(async (c, next) => { /* before */ await next() })
app.use("/admin/*", requireAdmin)
app.onError((err, c) => c.json({ error: "internal" }, 500))Throw new HTTPError(status, message) anywhere in a handler to return { error } with that status.
The request
c.req provides param(k), query(k), queries(k), header(k), await json(), await text(), await parseBody(), method, path, url and raw (the underlying Request).
Responses
c.json(data, status?, headers?),c.text,c.html,c.body,c.redirect(url),c.notFound(),c.status(n),c.header(k, v).- Returning a plain object sends it as JSON with status 200. Returning a
Responsealso works. - You cannot set
set-cookie, CORS headers or a Content Security Policy.
Calling from outside
- Send
Authorization: Bearer <key>with a project API key (thk_…) or a personal access token (ank_…). Keys limited to specific tables cannot call service routes. - CORS is open to every origin, without credentials.
- Request bodies are limited to 1 MB and responses to 2 MB.