Skip to content

Commit ce5ba87

Browse files
acn-ericlawclaude
andcommitted
docs: the REST Automation guide and the references, in lockstep with the Python pack
The documentation site gains docs/guides/rest-automation.md - the narrative of rest.yaml in the pack: turning it on, the file as the router, the function behind an entry with the AsyncHttpRequest accessors and the reply rules, what the edge does, the authentication function and the session map, streaming entries, the bounded upload, the static-content block, the default entries and the precedence, what a pack refuses and defers, the shipped examples and how to test an entry. The HTTP Surface Reference gains the entries' behaviour, the Configuration Reference the seven keys, the AI Agent Guide a pre-write checklist with a minimal entry and function and a DO/DON'T row, the index and llms.txt their entries, the nav the page, the configuration guide's static-content note the rest.yaml block. The twin of the Python pack's guide of the same day, section for section, in the Node idiom; every claim checked against the sources. CHANGELOG and the memory follow. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent fd74ba0 commit ce5ba87

11 files changed

Lines changed: 513 additions & 8 deletions

‎CHANGELOG.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,19 @@
393393
write after that is dropped as any write after `close()`. Beside it, `connected` (above) asks the question
394394
before a write.
395395

396+
### Documentation
397+
398+
1. **The documentation site gains the REST Automation guide, and the references follow, in lockstep with the Python
399+
pack.** `docs/guides/rest-automation.md` is the narrative of `rest.yaml` in the pack: turning it on, the file as
400+
the router, the function behind an entry with the `AsyncHttpRequest` accessors and the reply rules, what the edge
401+
does, the authentication function and the session map, streaming entries (the idle allowance, the keep-alive, a
402+
long-lived producer's `connected`), the bounded upload, the `static-content` block, the default entries and the
403+
precedence, what a pack refuses and defers, the shipped examples and how to test an entry. The HTTP Surface
404+
Reference gains the entries' behaviour, the Configuration Reference the keys (`rest.automation`,
405+
`yaml.rest.automation`, `rest.upload.max.bytes`, the three `http.*.header` names, `event.stream.keep.alive`), the
406+
AI Agent Guide a pre-write checklist with a minimal entry and function, the site index and `llms.txt` their
407+
entries. **Upgrade note:** none.
408+
396409
## 4.12.30 (2026-11-16)
397410

398411
The catch-up round with the engines: the pack moves from 4.12.21 to 4.12.30, the number the Java engine released on

‎docs/guides/ai-agent-guide.md‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: AI Agent Guide
33
summary: The complete authoring grammar for Node.js polyglot functions on one page -
44
contract, registration, config keys, endpoints and error rules, for deterministic generation.
55
audience: [ai-agent]
6-
keywords: [ai agent, grammar, contract, deterministic, preload, postoffice]
6+
keywords: [ai agent, grammar, contract, deterministic, preload, postoffice, rest automation, rest.yaml]
77
---
88

99
# AI Agent Guide
@@ -107,6 +107,57 @@ List the route in `mandatory.health.dependencies` (or `optional.…`).
107107
`POST /api/event` (envelope wire) · `GET /` `/info` `/info/routes` `/env` `/health`
108108
`/livenessprobe`. Shapes: [HTTP Surface Reference](http-surface-reference.md).
109109

110+
## REST automation (serve HTTP from `rest.yaml`, no engine needed)
111+
112+
Opt in with `rest.automation: true` in `resources/application.yml`; the router is
113+
`resources/rest.yaml` next to the application file, in the engines' grammar
114+
([REST grammar](https://accenture.github.io/mercury-composable/guides/rest-automation/rest-grammar/),
115+
[`rest-automation.json`](https://accenture.github.io/mercury-composable/guides/rest-automation/rest-automation.json)).
116+
Narrative: [REST Automation](rest-automation.md).
117+
118+
Pre-write checklist for an entry:
119+
120+
1. `service` is a function route of **this** application. Never `flow:` or
121+
`service: http.flow.adapter` (flows run in the engines), never an `http(s)://` relay,
122+
never a list of services — each is refused at load by name.
123+
2. `methods` from `GET PUT POST DELETE HEAD PATCH` (`OPTIONS` is auto-added); `url` with
124+
`{param}` segments or a trailing `*`; `timeout` 1 s–5 min (30 s default).
125+
3. The function reads `new AsyncHttpRequest(body)` — never the bare HTTP body — and replies
126+
with a value, an `EventEnvelope` (status, headers) or an `AppException` (the standard
127+
error body). A `null` the client must see → serialize the JSON yourself and set
128+
`content-type: application/json`.
129+
4. `authentication: '<route>'` names a function that returns `true` (its reply headers
130+
become `request.sessionInfo(...)`) or throws `AppException(401, ...)`.
131+
5. `stream: true` → an `interceptor: true` function writing through `EventStreamWriter`;
132+
`upload: true` → a `POST` entry, the files in `request.files()`, within
133+
`rest.upload.max.bytes`.
134+
6. Register the functions behind entries `isPrivate: true` when the edge is their only caller.
135+
7. A `cors:` or `headers:` value must match an `id` in the same file.
136+
137+
```yaml
138+
# resources/rest.yaml
139+
rest:
140+
- service: "order.enrich.rest"
141+
methods: ['POST']
142+
url: "/api/orders/{id}/enrich"
143+
timeout: 15s
144+
tracing: true
145+
```
146+
147+
```javascript
148+
import { AppException, AsyncHttpRequest, EventEnvelope, preload } from 'mercury-composable';
149+
150+
preload('order.enrich.rest', { instances: 10, isPrivate: true }, async (_headers, body) => {
151+
const request = new AsyncHttpRequest(body);
152+
const orderId = request.pathParameter('id');
153+
const payload = request.body; // the parsed JSON body
154+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) {
155+
throw new AppException(400, 'the body must be a JSON map');
156+
}
157+
return new EventEnvelope().setStatus(200).setBody({ id: orderId, enriched: true });
158+
});
159+
```
160+
110161
## Engine-side wiring (for completeness; authored on the engine)
111162

112163
```yaml
@@ -130,3 +181,4 @@ graph.task). Details: [Join an Event Script Flow](join-event-script.md) ·
130181
| keep functions stateless | cache business state in module globals |
131182
| compose one or two leaf helpers | re-implement flows/retries in Node.js |
132183
| let deadlines fail fast (408 envelope) | swallow timeouts and hoard work |
184+
| a `rest.yaml` entry for an HTTP path | mount a `node:http` route (`Platform.addRoutes` is the escape hatch for a WebSocket) |

‎docs/guides/config-logging-actuators.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ a bundle ships — and is `application/octet-stream` otherwise; every file carri
158158
answers `If-None-Match` with 304, and HTML is served `Cache-Control: no-cache`, so a redeployed
159159
page is revalidated while hashed assets stay cached. Never found, in the engines' error shape: a
160160
hidden entry (a segment starting with `.`, so `..` too), a symbolic link that leaves the folder,
161-
anything that is not a regular file. Not ported from the Java engine: the static-content filter,
162-
the `no-cache-pages` list and the `mime.types` section.
161+
anything that is not a regular file. With [REST automation](rest-automation.md#static-content) on,
162+
the `static-content` block of `rest.yaml` applies to this folder — the `no-cache-pages` list and
163+
the `filter` function — as in the Java engine; its `mime.types` section is not ported.
163164

164165
## Kubernetes wiring
165166

‎docs/guides/configuration-reference.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ keywords: [configuration, reference, keys, substitution, overrides]
3333
| `show.application.properties` | opt-in list of configuration keys shown by `/env` | (empty) |
3434
| `mandatory.health.dependencies` | routes of health check functions that decide `/health` | (empty) |
3535
| `optional.health.dependencies` | health check routes reported but never affecting status | (empty) |
36+
| `rest.automation` | REST automation on: the entries of `rest.yaml` served in front of the functions ([guide](rest-automation.md)) | `false` |
37+
| `yaml.rest.automation` | the one location of `rest.yaml`: `classpath:` the resources folder, `file:` an absolute path, a relative path under the application file's folder | `classpath:/rest.yaml` |
38+
| `rest.upload.max.bytes` | the bound on the files of one upload entry, together (413 beyond it) | `16777216` |
39+
| `http.trace.id.header` | the trace-id header a traced entry reads when no W3C `traceparent` arrives (`trace.id.header` overrides it per entry) | `X-Trace-Id` |
40+
| `http.correlation.id.header` | the business correlation-id header, always ensured and echoed (`correlation.id.header` per entry) | `X-Correlation-Id` |
41+
| `http.traceparent.header` | a custom name for the W3C `traceparent` header, read only when the standard one is absent (`traceparent.header` per entry) | `traceparent` |
42+
| `event.stream.keep.alive` | the keep-alive comment interval of a Server-Sent Events reply (`/api/event` and streaming entries); `0` disables | `30s` |
3643
| `static.html.folder` | the folder of static web content the host serves for the paths nothing else claims — relative to the application file's folder ([guide](config-logging-actuators.md#static-content-the-engines-public-folder)) | `resources/public` |
3744
| `otel.forwarding` | the OpenTelemetry forwarder's master switch ([guide](config-logging-actuators.md#distributed-tracing-the-opentelemetry-forwarder-opt-in)) | `false` |
3845
| `otel.exporter.otlp.endpoint` | the OTLP/HTTP traces URL including the signal path | `http://localhost:4318/v1/traces` |

‎docs/guides/http-surface-reference.md‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: HTTP Surface Reference
33
summary: The exact protocol and response shapes of the function host - Event API, actuators,
44
error signature and content types.
55
audience: [developer, operator, ai-agent]
6-
keywords: [http, reference, event api, actuator, error shape, content type]
6+
keywords: [http, reference, event api, actuator, rest automation, rest.yaml, error shape, content type]
77
---
88

99
# HTTP Surface Reference
@@ -47,6 +47,22 @@ reports `status_code: 404` with `Please check - Route X not found`.
4747
uuid (the Java reference engine's format).
4848
- `up_time` — the engines' rendering (`59 seconds`, `1 minute 1 second`, …).
4949

50+
## REST automation entries (opt-in)
51+
52+
With `rest.automation: true` ([guide](rest-automation.md)) the entries of `rest.yaml` are served
53+
first, in the engines' grammar; `POST /api/event` and the actuators are the default entries.
54+
55+
| Aspect | Behavior |
56+
|--------|----------|
57+
| Matching | the engines' precedence — the most specific route wins, `{param}` and a trailing `*`; a known path under another method → 405 `Method not allowed`; an unknown path → 404 `Resource not found`; `OPTIONS` → 204 with the entry's CORS `options` lines, 405 without a CORS block |
58+
| Request to the function | the whole request as the `AsyncHttpRequest` map — method, url, headers (lowercased, after the request transform), path and query parameters (a form's fields among them), the body parsed by its content type (JSON → map or list, text types → text, else bytes), cookies, the `session` map an authentication function left; `x-ttl` carries the entry's timeout in ms |
59+
| Reply | a returned value is the body; a returned `EventEnvelope` sets the status and headers (`set-cookie` values split on `\|`); the content type is the function's or negotiated from `Accept` (`text/html` wraps a map in the HTML shell; no `Accept` → no content type); a map or list is pretty-printed JSON with `null` entries omitted |
60+
| Errors | the engines' body below with `content-type: application/json`: an `AppException` from the function or the authentication function (anything but `true` from the latter → 401 `Unauthorized`); 408 `Timeout for N ms` at the entry's timeout (1 s–5 min, 30 s default; an inbound `x-ttl` wins); 503 `Service X not reachable` for an unregistered function; 413 `Upload exceeds N bytes` |
61+
| Correlation and tracing | `X-Correlation-Id` (or `http.correlation.id.header`) always ensured and echoed, delivered as `my_correlation_id`; with `tracing: true` a W3C `traceparent`, else `X-Trace-Id` (`http.trace.id.header`), else a fresh id, and the `http.request` record plus the function's round-trip record |
62+
| `stream: true` | an interceptor's segments rendered progressively: Server-Sent Events (`event:`/`data:` frames, `event: done` at the end, `event: error` in band, `: ping` keep-alives every `event.stream.keep.alive`) for a `text/event-stream` head or `Accept`, chunked text or JSON lines otherwise; the entry's timeout is the idle allowance, the head's `x-ttl` overrides it; a keep-alive that cannot be written ends the stream |
63+
| `upload: true` | a `POST` entry's `multipart/form-data` files in the request map (`filename`, `file_type`, `file_length`, `upload`, `size`, bytes in `contents`), the form's text fields as query parameters, no body; all files together within `rest.upload.max.bytes` (16 MiB) |
64+
| Precedence | a `rest.yaml` entry, then an extension's mounted routes (`Platform.addRoutes`), then the static folder (under the `static-content` block's `no-cache-pages` and `filter`), then the error signature below |
65+
5066
## Static content
5167

5268
A `GET` or `HEAD` of any other path is answered with the file it names inside `static.html.folder`
@@ -70,4 +86,5 @@ pretty-printed JSON:
7086
}
7187
```
7288

73-
Handler-level errors never use this shape — they ride the envelope on `/api/event`.
89+
Handler-level errors never use this shape on `/api/event` — they ride the envelope. Behind a
90+
`rest.yaml` entry a function's `AppException` *does* render as this shape, as in the engines.

0 commit comments

Comments
 (0)