Real traffic, not test traffic
restep-check makes up its own requests. restep-proxy watches the ones you already have: your app, your integration tests, an agent poking at the API. It finds what real clients actually run into.
Tools · Keep it compatible · v0.2.0
restep-proxyWatch the wirePut it in front of your API. Traffic goes through untouched while every exchange is checked against the specification and the discovery document, with the section for each finding.
Node 18 or later · npm install -g restep-proxy
restep-check makes up its own requests. restep-proxy watches the ones you already have: your app, your integration tests, an agent poking at the API. It finds what real clients actually run into.
Bodies, statuses and headers go through untouched, streamed. It only drops hop-by-hop headers and rewrites Host. Apart from one GET to the root at startup, it sends nothing of its own.
From media types and error format to filters, sorting, relations, actions, singletons, If-Match, Idempotency-Key and caching. Each finding names the check, the section of the specification and the request that broke it.
With --strict, a response that breaks a MUST becomes a 502 problem that lists why. Your tests fail at the exact request, not three steps later.
GET to the API root to read the discovery document (with Authorization: Bearer if RESTEP_TOKEN is set). If it cannot, it assumes only core until one goes through the proxy; every GET to the root that passes updates it. A document whose restep does not follow the grammar of §1.1, or is not Restep 1, is not used. The experimental parts (sync, inherit) are only judged under "1.0-draft.6", the draft whose text the proxy knows (§1.2).Connection, Keep-Alive, Transfer-Encoding, TE, Trailer, Upgrade, Proxy-Authorization, Proxy-Authenticate and whatever Connection names) are dropped, and Host becomes the target’s unless you pass --preserve-host.--max-body of the body, decompresses it (gzip, deflate, br) and checks the request and response pair against the specification and the discovery document. The response is only closed after the analysis, so what it learned is up to date before the same client’s next request.Idempotency-Key. That is how it catches an If-Match with a stale ETag that was not rejected, or a replay with a different body. It skips the comparison while another write on the same item is in flight, and does not judge a key whose first response was not 2xx, because the server MAY not store it./_restep-proxy, a JSON report, and a summary when you stop it. A broken MUST is a violation; a broken SHOULD, a warning.If the target does not answer, the proxy replies 502 problem+json with bad_gateway. That is not counted as a violation: the API was not there to break anything.
Node 18 or later, no dependencies. Run it with npx, or install it with npm install -g restep-proxy (or npm install --save-dev restep-proxy in a project).
npx restep-proxy --target http://localhost:8080 --port 8871
curl -g 'http://localhost:8871/books?filter[price][le]=15' # send your traffic to the proxy
If the API root is not the host’s root, give its path: --target http://api:8080/v1/. Paths are forwarded as they are. Stop it with Ctrl+C to get the summary.
Its log, its summary page and its messages are in Spanish for now, on this page too. Check names, sections and levels (DEBE is MUST, DEBERÍA is SHOULD) read the same in any language.
The reference server with two bugs planted on purpose: a 404 with its own code, and a limit above max_limit accepted instead of rejected. Seven requests went through the proxy; three of them found something.
$ npx restep-proxy --target http://localhost:8080 --port 8871 --report report.json
restep-proxy 0.2.0 en http://127.0.0.1:8871/ → http://localhost:8080/
descubrimiento leído (1.0-draft.6): core, query, writes, cache, inherit; 3 colecciones, 1 singletons. Resumen en http://127.0.0.1:8871/_restep-proxy
07:17:46 VIOLACIÓN limit (6.4, DEBE) GET /books
GET /books?limit=51 → 200: limit=51 fuera de 1..50 y aceptado; se esperaba invalid_parameter
07:17:46 VIOLACIÓN error.code (5.4, DEBE) GET /books/{id}
GET /books/nope → 404: code "missing" para 404; se esperaba not_found
07:17:46 VIOLACIÓN error.code (5.4, DEBE) PATCH /books/{id}
PATCH /books/nope → 404: code "missing" para 404; se esperaba not_found
^C
restep-proxy · resumen (http://localhost:8080/)
7 intercambios, 7 analizados
VIOLACIÓN 2× error.code (5.4) GET /books/{id}
GET /books/nope → 404: code "missing" para 404; se esperaba not_found
VIOLACIÓN 1× limit (6.4) GET /books
GET /books?limit=51 → 200: limit=51 fuera de 1..50 y aceptado; se esperaba invalid_parameter
VIOLACIÓN 1× error.code (5.4) PATCH /books/{id}
PATCH /books/nope → 404: code "missing" para 404; se esperaba not_found
4 violaciones en 3 grupos, 0 avisos
The second GET /books/nope2 did not print a new line: the log groups by check, method and route (/books/{id}), shows the first case, and after that only a reminder at 10, 100, 1000… repetitions. The summary counts them all. It exits with 1, because there were violations.
You do not have to stop it to see how things are going. Open http://localhost:8871/_restep-proxy in a browser: an HTML page with the totals and every group, which refreshes itself every 10 seconds. The same report, as JSON, is at /_restep-proxy.json:
$ curl -s http://localhost:8871/_restep-proxy.json
{
"tool": "restep-proxy",
"version": "0.2.0",
"target": "http://localhost:8080/",
"strict": false,
"discovery": { "restep": "1.0-draft.6", "profiles": ["core", "query", "writes", "cache"], "extensions": ["inherit"], "collections": ["categories", "products", "books"] },
"exchanges": 7,
"analysed": 7,
"by_status": { "2xx": 4, "4xx": 3 },
"upstream_errors": 0,
"replaced": 0,
"violations": 4,
"warnings": 0,
"groups": [
{
"check": "error.code",
"section": "5.4",
"level": "DEBE",
"spec": "https://restep.wubytes.com/1/#errors",
"method": "GET",
"route": "/books/{id}",
"count": 2,
"first": { "request": "GET /books/nope", "status": 404, "message": "code \"missing\" para 404; se esperaba not_found", … },
"last": { "request": "GET /books/nope2", … }
},
…
]
}
Both paths are answered by the proxy itself and never reach your API. --report report.json writes this same report when the proxy stops.
With --strict, the proxy holds each response until it has checked it. If it breaks a MUST, the client gets this instead:
$ curl -i http://localhost:8871/books/nope
HTTP/1.1 502 Bad Gateway
Content-Type: application/problem+json
Cache-Control: no-store
{"type":"about:blank","title":"La respuesta de la API incumple Restep","status":502,"code":"bad_gateway",
"detail":"restep-proxy --strict: 1 violación(es) en la respuesta 404 a GET /books/nope: error.code: code \"missing\" para 404; se esperaba not_found",
"upstream_status":404,
"violations":[{"check":"error.code","section":"5.4","spec":"https://restep.wubytes.com/1/#errors","message":"code \"missing\" para 404; se esperaba not_found"}]}
Warnings never replace anything. Holding the response adds latency, so a text/event-stream or a body larger than --max-body is still delivered without waiting.
npx restep-proxy --target http://localhost:8080 --port 8871 \
--report restep-proxy.json --strict --quiet &
PROXY=$!
API_URL=http://localhost:8871 npm test # your tests, pointed at the proxy
kill -INT $PROXY; wait $PROXY # exits with 1 if there was any violation
Your tests do not need to know anything about Restep: they only need to talk to the proxy. Keep restep-proxy.json as a build artifact.
| Option | What it does |
|---|---|
--target <url> | The API to forward to. Required. With its path if the API root is not the host’s: http://api:8080/v1/ |
--port <n> | Port the proxy listens on (8871) |
--host <host> | Interface it listens on (127.0.0.1) |
--report <file> | Writes the JSON report when it stops |
--strict | Replaces every response that breaks a MUST with a 502 problem+json |
--max-body <bytes> | Largest body it analyses (2097152, 2 MiB). Larger ones are forwarded without analysis |
--preserve-host | Forwards the client’s Host instead of the target’s |
--quiet | No live log, only the final summary |
-h, --help | A short help |
| Also | What it is |
|---|---|
RESTEP_TOKEN | Environment variable. The startup GET to the discovery document carries Authorization: Bearer with it. Client traffic goes through with its own credentials |
GET /_restep-proxy | The summary as an HTML page, refreshed every 10 seconds |
GET /_restep-proxy.json | The report as JSON, without stopping the proxy: violations, warnings, and groups with check, section, level, spec, method, route, count, first and last |
It stops on SIGINT or SIGTERM and exits with 0 without violations, 1 with any, and 2 if it cannot start.
Each one names its section of draft 6 of the specification. The ones that depend on discovery (collections, singletons, filters, profiles) only run when there is one. Those for cache (cache-control, cache-etag, if-none-match on reads) only run when cache is announced, and those for writes only when writes is: since draft 6, Cache-Control and 304 belong to cache. The experimental parts (sync, inherit) are only judged under "1.0-draft.6", the one draft whose text the proxy knows. The § column links to each section.
| Check | What it verifies | Level | § |
|---|---|---|---|
json | A JSON body is valid JSON in UTF-8, compressed or not | MUST | §3 |
json-type | A 2xx with a body carries Content-Type: application/json (a schema may come as application/schema+json) | MUST | §3 |
media-type | A POST or QUERY whose body has no Content-Type, another type or a charset other than UTF-8, or a PATCH of another type, gives 415; an empty body with application/json gives 400 | MUST | §3 |
links | next and href are absolute URIs or absolute paths under the API root, and an absolute URI (in Location and Link too) uses https or the root’s scheme | MUST | §3 |
discovery.version | The restep of discovery follows the grammar major.minor[-draft.N|-rc.N] and is Restep 1 | MUST | §1.1 |
profile-link | Every response carries a single rel="profile" link, to the version URI | SHOULD | §4.1 |
item.discovery | Items fit discovery: declared types, language maps, relationships and inheritance | MUST | §4.2 |
allow | A 405 names in Allow the declared methods and no others; a declared method never gives 405 | MUST | §4.3 |
health | The status resource answers 200 or 503 with Cache-Control: no-store (or 401, 403, 429) | MUST | §4.4 |
| Check | What it verifies | Level | § |
|---|---|---|---|
status.success | Successes use the table’s status: GET 200, POST 201, PATCH 200 (204 with return=minimal), DELETE 204 | MUST | §5.1 |
location | A 201 carries Location with the item’s path: its collection’s, / and its id | MUST | §5.1 |
id.assigned | A PATCH with another id gives 422; so does a POST with an id where id_from does not allow it, and one without where id_from is "client" | MUST | §5.1 |
patch.object | A patch that is not a JSON object gives 400, not success | MUST | §5.1 |
media-type.accept-patch | A 415 to a PATCH carries Accept-Patch | SHOULD | §5.1 |
error.405 | A 405 carries Allow | MUST | §5.1 |
cache-private.auth | A 401 or a 403 is private or no-store | MUST | §5.1 |
cache-private | A response to a request with credentials is private or no-store | MUST | §5.1 |
collection.shape | A collection responds {items, next}, with next present (string or null) | MUST | §5.2 |
reserved | A reserved parameter the resource does not implement gives 400 unsupported_parameter; it is not ignored | MUST | §5.3 |
query.declared-rejected | A declared filter, sort or count is not rejected with unsupported_parameter | MUST | §5.3 |
query.undeclared | An undeclared filter field or operator, or sort field, gives unsupported_parameter | MUST | §5.3 |
error.parameter | invalid_parameter and unsupported_parameter name the parameter as received | MUST | §5.3 |
| Check | What it verifies | Level | § |
|---|---|---|---|
error.media-type | 4xx and 5xx with a body use application/problem+json | MUST | §5.4 |
error.schema | The error body fits the problem.json schema | MUST | §5.4 |
error.status | The body’s status is the response’s | MUST | §5.4 |
error.code | code comes from the table for that status, the IANA registry or http_NNN | MUST | §5.4 |
error.type | type is the Restep error URI for that code, another URI or about:blank | SHOULD | §5.4 |
error.detail | Errors carry detail | SHOULD | §5.4 |
error.401 | A 401 carries WWW-Authenticate | MUST | §5.4 |
error.retry-after | A 429, a 503 or a 409 request_in_progress (7.1) carries Retry-After | SHOULD | §5.4 |
error.reason | reason follows the grammar of names and, if discovery declares reasons, is one of them, with its code | MUST | §5.4 |
no-error-in-200 | No problem object inside a 2xx | MUST | §5.4 |
deprecation | What discovery deprecates carries Deprecation and a Link rel="deprecation" (and Sunset if it is a resource, an action or the version); after the date it no longer works | MUST | §5.5 |
singleton | A singleton answers GET with a JSON object, and POST and DELETE with 405 | MUST | §5.9 |
| Check | What it verifies | Level | § |
|---|---|---|---|
relations.link | A link of a relation to several collections carries type (one of them), and one to an item of a subcollection carries href, that item’s path | MUST | §9 |
relations.include | include of a relation that is not declared, not expandable, deeper than include_depth or going on past a relation to several collections gives unsupported_parameter | MUST | §9 |
relations.fields | A dotted path in fields whose relation is not in include gives invalid_parameter | MUST | §9 |
actions.listed | Every action in _actions is declared in the collection, on items and with the same method | MUST | §11.1 |
actions.undeclared | An action that is not declared, or declared on the other kind of resource, gives 404; with another method, 405 | MUST | §11.1 |
actions.response | An action answers 200 (the affected resource), 201 with Location (a new one) or 204 | MUST | §11.1 |
actions.empty-body | A POST action takes an empty body, with or without Content-Type, as {}: never 400 or 415 because of it | MUST | §11.1 |
| Check | What it verifies | Level | § |
|---|---|---|---|
query.named-value | A switch with a value, or a named filter with a type and no value or one that does not fit, gives invalid_parameter | MUST | §6.1 |
filter.match | Every item returned matches the filters, compared by the declared type (exact decimals) | MUST | §6.1 |
sort.order | Items come in the requested order, with those without a value last | MUST | §6.2 |
fields | With fields, only those fields, id and the members starting with _ | MUST | §6.3 |
limit | A page is no longer than limit, and a limit outside 1..max_limit gives invalid_parameter | MUST | §6.4 |
next | next carries cursor and keeps the other parameters unchanged | MUST | §6.4 |
count | count=true adds total, an integer; with count exact, no total_estimated | MUST | §6.5 |
The ones that compare requests with each other use what the proxy learned from earlier traffic.
| Check | What it verifies | Level | § |
|---|---|---|---|
idempotency.key | A malformed Idempotency-Key gives 400 bad_request; with "anonymous": false, so does one without credentials (except on an idempotent action, which ignores it); an idempotent action does not reject a well-formed one | MUST | §7.1 |
idempotency.replay | The same request with the same Idempotency-Key returns the same status and the same body | MUST | §7.1 |
idempotency.replayed-header | A replay carries Idempotent-Replayed: true | SHOULD | §7.1 |
idempotency.mismatch | The same Idempotency-Key with another request does not succeed (422 idempotency_mismatch) | MUST | §7.1 |
etag | The GET of a full item carries its strong ETag, and every response whose body is an item carries _etag | MUST | §7.2 |
etag.collection | Items in a collection carry _etag when they accept PATCH or DELETE | SHOULD | §7.2 |
etag.synced | In a collection that declares sync, every item that accepts PATCH or DELETE carries _etag, on every page | MUST | §7.2 |
if-match | If-Match with an old ETag gives 412; with the current one, it does not; a write to an item just deleted gives 404, not 412 | MUST | §7.2 |
precondition | A 412 answers a conditional header, and a 428 a write without If-Match | MUST | §7.2 |
minimal.etag | A minimal response to a write that does not delete carries the item’s ETag | MUST | §7.3 |
minimal | A minimal response carries Preference-Applied | SHOULD | §7.3 |
| Check | What it verifies | Level | § |
|---|---|---|---|
if-none-match | A matching If-None-Match gives 304 to GET and HEAD (cache) and 412 to a write (writes) | MUST | §8 |
cache-control | With cache, every response to GET or HEAD, errors included, carries Cache-Control | MUST | §8 |
cache-etag | With cache, the GET of a full item or of a singleton carries ETag | MUST | §8 |
sync.undeclared | :changes on a collection that does not declare sync gives 404 | MUST | §10 |
events | The response from events carries Cache-Control: no-store | MUST | §10 |
Upgrade (WebSocket).--max-body.if-match can take an ETag for stale when it no longer is.include fills in the object (a related item the client cannot see stays as its id, and the proxy cannot tell which) or that an href leads to an item that exists; of actions, neither the 422 against their input nor that _actions lists only what is available in the item’s state; nor batch, filter-expr or query-method, nor Accept-Language and Vary (5.6), nor that a full traversal has no repeats or gaps. Of sync it only checks that :changes gives 404 on a collection without sync, the _etag of synced items and the Cache-Control of events; not the content of :changes or the events. restep-check does most of the rest.If-Match on a POST to a collection (7.2), cache groups (8), the Origin check of 5.8, the href in a singleton’s relationships, or that a 429 or 503 only reaches requests that had no effect (5.7).Authorization as credentials for cache-private, not cookies or client certificates, and cannot know whether the response really depends on them, so it asks for more than the text does.Compares two discovery documents and sorts every change into breaking, deprecation or compatible. Ready for a changelog or a pull request.
A GitHub Action: starts your API, runs restep-check and restep-diff, and keeps one comment on the pull request up to date.