Use koa-requestid as a middleware for a koa app. By default, it generates a unique uuid (v4) and exposes it on the response via the Request-Id header. The id is also saved as part of the request state.
In the following example, the generated uuid is manually exposed on the body for debugging purposes:
Sometimes it is also useful to pass a custom id via a request header or query string, specifically in debugging sessions. Please note that the input id is not sanitized, so the usual precautions apply.
Using the above snippet to send a custom via the default Request-Id header:
This configuration would expose every generated request id via the X-Request-Id response header and accept a custom id via the X-Req-Id header or request-id query string parameter.
Tests
❯ yarn test
Release
npm version [<new version> | major | minor | patch] -m "Release %s"