Skip to content

RequestId

RequestId provides app-host middleware that assigns a request ID and can write it to the response.

Import:

ts
import { RequestId } from "sloppy";

RequestId.defaults(options?)

ts
app.use(RequestId.defaults());

Default behavior:

  • generated IDs use req-<number>;
  • incoming request IDs are ignored;
  • ctx.requestId is available to later middleware and handlers;
  • x-request-id is written to the response.

Options:

OptionDefaultBehavior
header"x-request-id"Header name to read/write. Must be a safe unmanaged HTTP header name.
responseHeadertrueWrites the response header when enabled.
trustIncomingfalseUses a safe incoming header value when enabled.
generatorinternal counterFunction that returns a safe non-empty request ID.

Managed headers such as content-type, content-length, connection, transfer-encoding, and keep-alive cannot be used as the request ID header. Incoming or generated values with control characters are rejected or ignored.

The compiler accepts the static middleware subset shown above; anything more dynamic is rejected at build time with a diagnostic instead of being silently dropped.

Public alpha. APIs and artifact formats may still change between alpha revisions.