Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

HTTP & JSON

Returning JSON

get "/health" {
  def health(req) {
    return ok({ "status": "ok" })
  }
}

post "/items" {
  def create(req) {
    let body = require_json(req)
    require_fields(body, ["name"])
    return created({ "id": 1, "ok": true })
  }
}

json(body) and ok(body) are equivalent (HTTP 200). Prefer created(body) for 201 and json(body, code) when you need another status.

Status-only

return no_content()   // 204
// or: return status(204)

Path params

get "/users/{id}" {
  def show(req) {
    let id = req.param("id")
    return ok({ "id": id })
  }
}

Headers

let auth = req.header("authorization")
// or early-exit: let uid = require_auth(req)

Content types

HelperTypical Content-Type
json(...) / ok(...) / created(...)application/json
html(...) / view(...)text/html; charset=utf-8

Errors

Unhandled runtime errors become 500 JSON with a request_id. Prefer explicit helpers (stable error codes):

return not_found()
return not_found("user missing")
return unauthorized()
return forbidden("no access")
return bad_request("bad id")
return unprocessable({ "email": "required" })

These desugar to http_json_response with { error, message? } or { error: "validation_failed", fields? }. Classic json({ "error": "not_found" }, 404) still works.

CORS & body limits

EnvMeaning
ATL_CORS_ORIGINSComma-separated origins
ATL_MAX_BODY_BYTESMax body size (default ~10 MiB)

Next: HTML views · Natives.