RatMinimal web framework

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 is a > server block. The whole block serializes to JSON on a GET request. Use it for health checks, build metadata, or anything that needs no 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 become callable endpoints at /api/<file>/<name>. POST a JSON array for positional args, or a JSON object for a single arg. The return value becomes the response body.

# api/user.rat
> server
user_cap: 1000

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

> 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>(...) with no HTTP hop. So user.get_users() works the same from a page handler or another service.

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

<p> [count] users registered

See also Public endpoints · Queries · Middleware