Skip to content

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 { precondition } from "@centralping/ergo";
OptionTypeDefaultDescription
methodsstring[] | Set<string>Methods to enforce on; omit to enforce unconditionally

Returns undefined on success — the middleware is a gate.

StatusCondition
428 Precondition RequiredNeither If-Match nor If-Unmodified-Since header is present
import { compose, precondition } from "@centralping/ergo";
// Enforce on all methods
const pipeline = compose(
precondition(),
);
// Enforce only on PUT and PATCH
const pipeline = compose(
precondition({ methods: ["PUT", "PATCH"] }),
);

See the auto-generated precondition API docs.