Rat docs

API files

A .rat file under api/ becomes an HTTP endpoint under /api/. The filename maps to the route the same way pages/ does. > server declarations become the JSON body returned by a bare GET; > name functions become callable subpaths.

Static JSON endpoint

api/version.rat

The simplest endpoint: a > server block. The whole block is serialized to JSON on a GET request. Useful for health checks, build metadata, anything that doesn't need a function call.

# api/version.rat — served at /api/version
> server
name: 'rat-docs'
version: '0.2.0'
ok: true

Function endpoints

Subpath per function

Top-level > name functions in an API file become callable endpoints at /api/<file>/<name>. POST a JSON array (positional args) or JSON object (single-arg). Function returns become the response body.

# api/user.rat
> server
user_cap: 1000

> get_users[]
    << main_db.user.list()

> add_user[name, email]
    << main_db.user.add({name: name, email: email})

Call from a page

Same namespace works in-process

Inside Rat code, the same API functions are reachable as <file>.<name>(...) — no HTTP hop. So user.get_users() works from a page handler or another service identically.

> page
count >> len(user.get_users())

<p> [count] users registered

Next: Public endpoints — controlling which functions are reachable over HTTP.