AI agent guide — authoring rest.yaml¶
At a glance
- Read this if you are an AI agent asked to add or change an HTTP endpoint. It is the context you need — you should not have to read the parser source.
- Generate from rules. The REST grammar and its machine-readable form
rest-automation.jsonare the source of truth.rest.yamlis parsed and validated at startup (RoutingEntry); an invalid entry fails to load.
Decide the binding first¶
Pick how the endpoint reaches its backend, then fill the entry:
- Function →
service: <function.route>. - Flow →
service: http.flow.adapterandflow: <flow-id>. - HTTP relay →
service: https://host(single URL;url_rewrite/trust_all_certallowed). - In a language pack (Python, Node.js) only the Function binding exists — see Authoring for a language pack.
Generate deterministically¶
Look up exact fields/values in rest-automation.json; follow the rules in
rest-grammar.md. Then verify:
Pre-write checklist - [ ] The entry has
service,methods, andurl. - [ ]methodsare fromGET PUT POST DELETE HEAD PATCH— do not listOPTIONS(auto-added). - [ ] Binding is consistent: aflowusesservice: http.flow.adapter; anhttp(s)://relayserviceis a single URL. - [ ] Anycors:/headers:value matches an existingcors/headersidin the same file. - [ ]url_rewrite(if present) is a list of exactly two strings, and only on a relay service. - [ ]{param}tokens inurlare balanced and not nested.
Worked example¶
The canonical example below covers all three binding forms — a flow-backed endpoint with
reusable CORS and response-header configs, a function-backed endpoint with a path parameter,
and an HTTP relay with url_rewrite. This exact file is also loaded through the production
RoutingEntry parser in a platform-core test, so the example cannot drift from the router:
# The canonical rest.yaml worked example for the documentation guides.
#
# This exact file is included into the guides by mkdocs AND loaded through the production
# RoutingEntry parser in RoutingEntryGuideFixtureTest, so the documented example can never
# drift from what the REST automation engine actually accepts.
rest:
# A flow-backed endpoint needs BOTH keys: 'service' selects the flow adapter and
# 'flow' selects the flow. An entry with 'flow' alone has no service and is
# skipped as invalid at startup.
- service: 'http.flow.adapter'
flow: 'order-status'
methods: ['POST']
url: '/api/orders/{order_id}/status'
timeout: 30s
cors: cors_1
headers: header_1
tracing: true
# A function-backed endpoint with a path parameter
- service: 'profile.lookup'
methods: ['GET']
url: '/api/profile/{id}'
timeout: 10s
# An HTTP relay: 'service' is a single URL and 'url_rewrite' maps the inbound
# path prefix to the upstream path
- service: 'https://example.org'
methods: ['GET']
url: '/api/upstream/orders'
url_rewrite: ['/api/upstream', '/v1']
timeout: 20s
tracing: true
cors:
- id: cors_1
options:
- 'Access-Control-Allow-Origin: *'
- 'Access-Control-Allow-Methods: GET, POST, OPTIONS'
- 'Access-Control-Allow-Headers: Origin, Authorization, Content-Type'
headers:
- 'Access-Control-Allow-Origin: *'
headers:
- id: header_1
response:
add:
- 'x-powered-by: mercury'
drop:
- 'server'
A traced endpoint serving a legacy caller that uses its own trace/correlation header names
(per-endpoint impedance matching — the optional trace.id.header / correlation.id.header /
traceparent.header keys override the global http.trace.id.header / http.correlation.id.header /
http.traceparent.header names for this entry only; the standard W3C traceparent always takes
precedence, and a custom traceparent.header name is read only when the standard header is
absent. These overrides are for backward compatibility with legacy systems only — the standard
W3C/OTel traceparent needs no configuration and departing from it is discouraged):
rest:
- service: 'legacy.orders'
methods: ['POST']
url: '/api/legacy/orders'
timeout: 15s
tracing: true
trace.id.header: 'X-Legacy-Trace'
correlation.id.header: 'X-Legacy-Cid'
Authoring for a language pack¶
A rest.yaml served by the Python or Node.js pack (RFC-0018) follows this grammar with one binding and a few
boundaries; the file lives at resources/rest.yaml next to the application file and is read when the pack's
application.yml sets rest.automation: true.
Pre-write checklist (pack) - [ ]
serviceis a function route of the pack application — neverflow:orservice: http.flow.adapter, never anhttp(s)://relay, never a list (each fails the load by name). - [ ] The function reads theAsyncHttpRequestmap (AsyncHttpRequest(body)in Python,new AsyncHttpRequest(body)in Node.js), never the bare HTTP body, and replies with a value, an envelope (status, headers) or an exception (the standard error body). - [ ]authentication:names a function that returnstrue— its reply headers become the request'ssessionmap — or raises a 401. - [ ]stream: true→ an interceptor writing through the pack'sEventStreamWriter;upload: true→ aPOSTentry whose files arrive in the request map withinrest.upload.max.bytes. - [ ] Nocustom.content.types,mime.typesor XML (deferred);static-content'sno-cache-pagesandfilterapply;POST /api/eventand the actuators are the default entries.
rest:
- service: 'profile.lookup'
methods: ['GET']
url: '/api/profile/{id}'
timeout: 10s
authentication: 'api.key.check'
tracing: true
The function code for each language is in the packs' AI agent guides: Python · Node.js.
See also¶
- REST automation grammar +
rest-automation.json— the source of truth. - REST Automation — worked examples and the full feature set; in the language packs.
- The packs' REST Automation guides: Python · Node.js.