Documentation
Docs
Introduction
Getting Started
Tutorial: build an app
Core Concepts
Routing
Server-Side Rendering
Mimir, state management
Pages & Layouts
API Routes
Styling & Theming
Building & Deploying
API Reference
Guides
Recipes
FAQ (use cases)
API routes
A rune app is also your backend. app.api(method, path, [opts], handler) registers an HTTP endpoint in the
same process as your pages, no separate server, no CORS, no type boundary. The pages and the API read the
same in-memory data.
Signature
method,"GET" | "POST" | "PUT" | "DELETE" | "PATCH"(case-insensitive).path, the URL pattern, supports:paramsegments (/api/notes/:id).opts, optional per-route options (passed to the underlying server, e.g. body limits).handler,(req, res) => ....
Returns app, so you can chain.
Returning vs writing
The handler can return a value or write to res, returning is the concise path:
If the handler returns a value and has not already written to res, rune sends it: objects/arrays as JSON,
anything else as text. If you write to res yourself, return nothing.
Params
:param segments are parsed into req.params:
Errors are caught
If a handler throws, rune catches it, logs it server-side, and responds 500 { error } rather than crashing
the process. You can still set explicit statuses for expected errors:
The "same process" advantage
Because the API and the pages run together, you get patterns that are awkward in a split stack:
The page render, the API, and the cache live in one place: the API mutates the data the pages render, and busts the page cache directly. See Caching & invalidation.
Organising routes
Register routes wherever it reads best, all in server.tsx, or grouped into modules you call from
server.tsx:
Next: the request and response objects in detail, Request & response.