precondition
Enforces that unsafe requests include a conditional header (If-Match or
If-Unmodified-Since) before proceeding. Prevents lost-update problems
by requiring clients to prove they have a current representation.
Pipeline stage: Negotiation (Fast Fail)
Import
Section titled “Import”import { precondition } from "@centralping/ergo";Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
methods | string[] | Set<string> | — | Methods to enforce on; omit to enforce unconditionally |
Return Value
Section titled “Return Value”Returns undefined on success — the middleware is a gate.
Error Responses
Section titled “Error Responses”| Status | Condition |
|---|---|
| 428 Precondition Required | Neither If-Match nor If-Unmodified-Since header is present |
import { compose, precondition } from "@centralping/ergo";
// Enforce on all methodsconst pipeline = compose( precondition(),);
// Enforce only on PUT and PATCHconst pipeline = compose( precondition({ methods: ["PUT", "PATCH"] }),);router.put("/users/:id", { preconditionRequired: true, execute: (req, res, acc) => ({ response: { body: { updated: true } }, }),});RFC References
Section titled “RFC References”API Reference
Section titled “API Reference”See the auto-generated precondition API docs.