Skip to content

Commit 98d6896

Browse files
authored
Merge pull request #88 from Accenture/docs/rest-automation-guide
docs: the REST Automation guide on the documentation site, and the references follow
2 parents 498e9cd + bb0a0f9 commit 98d6896

11 files changed

Lines changed: 488 additions & 11 deletions

‎CHANGELOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,18 @@
397397
that reads these endpoints with its own client sees the error body gain `status`; nothing else changes. The Node
398398
pack follows.
399399

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

402414
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: 52 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 Python 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
@@ -105,6 +105,56 @@ List the route in `mandatory.health.dependencies` (or `optional.…`).
105105
`POST /api/event` (envelope wire) · `GET /` `/info` `/info/routes` `/env` `/health`
106106
`/livenessprobe`. Shapes: [HTTP Surface Reference](http-surface-reference.md).
107107

108+
## REST automation (serve HTTP from `rest.yaml`, no engine needed)
109+
110+
Opt in with `rest.automation: true` in `resources/application.yml`; the router is
111+
`resources/rest.yaml` next to the application file, in the engines' grammar
112+
([REST grammar](https://accenture.github.io/mercury-composable/guides/rest-automation/rest-grammar/),
113+
[`rest-automation.json`](https://accenture.github.io/mercury-composable/guides/rest-automation/rest-automation.json)).
114+
Narrative: [REST Automation](rest-automation.md).
115+
116+
Pre-write checklist for an entry:
117+
118+
1. `service` is a function route of **this** application. Never `flow:` or
119+
`service: http.flow.adapter` (flows run in the engines), never an `http(s)://` relay,
120+
never a list of services — each is refused at load by name.
121+
2. `methods` from `GET PUT POST DELETE HEAD PATCH` (`OPTIONS` is auto-added); `url` with
122+
`{param}` segments or a trailing `*`; `timeout` 1 s–5 min (30 s default).
123+
3. The function reads `AsyncHttpRequest(body)` — never the bare HTTP body — and replies
124+
with a value, an `EventEnvelope` (status, headers) or an `AppException` (the standard
125+
error body). A `null` the client must see → serialize the JSON yourself and set
126+
`content-type: application/json`.
127+
4. `authentication: '<route>'` names a function that returns `True` (its reply headers
128+
become `request.session_info(...)`) or raises `AppException(401, ...)`.
129+
5. `stream: true` → an `interceptor=True` function writing through `EventStreamWriter`;
130+
`upload: true` → a `POST` entry, the files in `request.files()`, within
131+
`rest.upload.max.bytes`.
132+
6. Register the functions behind entries `private=True` when the edge is their only caller.
133+
7. A `cors:` or `headers:` value must match an `id` in the same file.
134+
135+
```yaml
136+
# resources/rest.yaml
137+
rest:
138+
- service: "order.enrich.rest"
139+
methods: ['POST']
140+
url: "/api/orders/{id}/enrich"
141+
timeout: 15s
142+
tracing: true
143+
```
144+
145+
```python
146+
from mercury_composable import AppException, AsyncHttpRequest, Body, EventEnvelope, preload
147+
148+
@preload(route="order.enrich.rest", instances=10, private=True)
149+
async def enrich_rest(_headers: dict[str, str], body: Body):
150+
request = AsyncHttpRequest(body)
151+
order_id = request.path_parameter("id")
152+
payload = request.body # the parsed JSON body
153+
if not isinstance(payload, dict):
154+
raise AppException(400, "the body must be a JSON map")
155+
return EventEnvelope().set_status(200).set_body({"id": order_id, "enriched": True})
156+
```
157+
108158
## Engine-side wiring (for completeness; authored on the engine)
109159
110160
```yaml
@@ -128,3 +178,4 @@ graph.task). Details: [Join an Event Script Flow](join-event-script.md) ·
128178
| keep functions stateless | cache business state in module globals |
129179
| compose one or two leaf helpers | re-implement flows/retries in Python |
130180
| let deadlines fail fast (408 envelope) | swallow timeouts and hoard work |
181+
| a `rest.yaml` entry for an HTTP path | mount an aiohttp route (`Platform.add_routes` 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
@@ -155,8 +155,9 @@ a bundle ships — and is `application/octet-stream` otherwise; every file carri
155155
answers `If-None-Match` with 304, and HTML is served `Cache-Control: no-cache`, so a redeployed
156156
page is revalidated while hashed assets stay cached. Never found, in the engines' error shape: a
157157
hidden entry (a segment starting with `.`, so `..` too), a symbolic link that leaves the folder,
158-
anything that is not a regular file. Not ported from the Java engine: the static-content filter,
159-
the `no-cache-pages` list and the `mime.types` section.
158+
anything that is not a regular file. With [REST automation](rest-automation.md#static-content) on,
159+
the `static-content` block of `rest.yaml` applies to this folder — the `no-cache-pages` list and
160+
the `filter` function — as in the Java engine; its `mime.types` section is not ported.
160161

161162
## Kubernetes wiring
162163

‎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.add_routes`), 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)