{"id":20617678,"url":"https://github.com/uphold/koa-requestid","last_synced_at":"2025-04-15T11:30:04.716Z","repository":{"id":40745911,"uuid":"39604032","full_name":"uphold/koa-requestid","owner":"uphold","description":"A middleware that adds a request id to a koa application","archived":false,"fork":false,"pushed_at":"2024-02-21T02:28:09.000Z","size":372,"stargazers_count":13,"open_issues_count":1,"forks_count":3,"subscribers_count":55,"default_branch":"master","last_synced_at":"2025-03-28T19:21:38.615Z","etag":null,"topics":["koa2","middleware","request","tracing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uphold.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-24T01:28:43.000Z","updated_at":"2023-11-14T12:52:12.000Z","dependencies_parsed_at":"2023-11-13T19:29:05.195Z","dependency_job_id":"a4a89da8-e6b2-472a-9eb9-bad3c24f267f","html_url":"https://github.com/uphold/koa-requestid","commit_stats":{"total_commits":54,"total_committers":11,"mean_commits":4.909090909090909,"dds":0.6666666666666667,"last_synced_commit":"2032a9bd86c48f4059eff1f37c2b24bb95b29eab"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fkoa-requestid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fkoa-requestid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fkoa-requestid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fkoa-requestid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uphold","download_url":"https://codeload.github.com/uphold/koa-requestid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248768554,"owners_count":21158662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["koa2","middleware","request","tracing"],"created_at":"2024-11-16T12:05:38.878Z","updated_at":"2025-04-15T11:30:04.698Z","avatar_url":"https://github.com/uphold.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-requestid\n\n## Status\n\n[![npm version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n\n## Installation\n\nInstall the package via `yarn`:\n\n```sh\n❯ yarn add koa-requestid\n```\n\nor via `npm`:\n\n```sh\n❯ npm install koa-requestid --save\n```\n\n## Usage\n\nUse `koa-requestid` as a middleware for a [koa](https://github.com/koajs/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*.\n\nIn the following example, the generated uuid is manually exposed on the body for debugging purposes:\n\n```js\nconst Koa = require('koa');\nconst requestId = require('koa-requestid');\nconst app = new Koa();\n\napp.use(requestId());\napp.use(async ctx =\u003e {\n  ctx.body = ctx.state.id;\n});\n\napp.listen(3000);\n```\n\nExecute a request to the running app:\n\n```bash\n❯ curl -v http://localhost:3000\n\n\u003c HTTP/1.1 200 OK\n\u003c Request-Id: cc0f12c7-f3b6-4c86-94c2-8c4ce7751651\n\ncc0f12c7-f3b6-4c86-94c2-8c4ce7751651\n```\n\nSometimes 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.\n\nUsing the above snippet to send a custom via the default `Request-Id` header:\n\n```bash\n❯ curl -v -H 'Request-Id: foobar' http://localhost:3000\n\n\u003c HTTP/1.1 200 OK\n\u003c Request-Id: foobar\n\nfoobar\n```\n\nor using a query string parameter (default is `requestId`):\n\n```bash\n❯ curl -v http://localhost:3000?requestId=foobar\n\n\u003c HTTP/1.1 200 OK\n\u003c Request-Id: foobar\n\nfoobar\n```\n\n## Configuration\n\n#### Arguments\n1. `options` *(object)*: A dictionary of options.\n\n#### Options\n1. `expose` *(string|false)*: The name of the header to expose the id on the response, or `false` to disable.\n2. `header` *(string|false)*: The name of the header to read the id on the request, or `false` to disable.\n3. `query` *(string|false)*: The name of the header to read the id on the query string, or `false` to disable.\n\nExample:\n\n```js\nconst Koa = require('koa');\nconst requestId = require('koa-requestid');\nconst app = new Koa();\n\napp.use(requestId({\n  expose: 'X-Request-Id',\n  header: 'X-Req-Id',\n  query: 'request-id'\n}));\n```\n\nThis 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.\n\n## Tests\n\n```\n❯ yarn test\n```\n\n## Release\n\n```sh\nnpm version [\u003cnew version\u003e | major | minor | patch] -m \"Release %s\"\n```\n\n## License\n\nMIT\n\n[npm-image]: https://img.shields.io/npm/v/koa-requestid.svg\n[npm-url]: https://www.npmjs.com/package/koa-requestid\n[travis-image]: https://travis-ci.org/uphold/koa-requestid.svg?branch=master\n[travis-url]: https://travis-ci.org/uphold/koa-requestid\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuphold%2Fkoa-requestid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuphold%2Fkoa-requestid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuphold%2Fkoa-requestid/lists"}