{"id":15097840,"url":"https://github.com/kasa-network/koa-http-client","last_synced_at":"2025-10-08T02:31:54.872Z","repository":{"id":57124021,"uuid":"171831939","full_name":"kasa-network/koa-http-client","owner":"kasa-network","description":"💬 HTTP Client to communicate with the context during inter-service communications in Koa","archived":true,"fork":false,"pushed_at":"2020-07-13T22:08:56.000Z","size":13,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-01-05T12:09:20.200Z","etag":null,"topics":["got","http-client","httpclient","koa","koa-middleware","koajs"],"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/kasa-network.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}},"created_at":"2019-02-21T08:32:52.000Z","updated_at":"2023-01-28T08:42:20.000Z","dependencies_parsed_at":"2022-08-26T04:22:35.203Z","dependency_job_id":null,"html_url":"https://github.com/kasa-network/koa-http-client","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasa-network%2Fkoa-http-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasa-network%2Fkoa-http-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasa-network%2Fkoa-http-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kasa-network%2Fkoa-http-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kasa-network","download_url":"https://codeload.github.com/kasa-network/koa-http-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235674061,"owners_count":19027515,"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":["got","http-client","httpclient","koa","koa-middleware","koajs"],"created_at":"2024-09-25T16:40:53.435Z","updated_at":"2025-10-08T02:31:49.536Z","avatar_url":"https://github.com/kasa-network.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e@kasa/koa-http-client\u003c/h1\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  A middleware that attachs HTTP client to communicate with the context during inter-service communications in Koa.\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://circleci.com/gh/kasa-network/koa-http-client\"\u003e\n    \u003cimg alt=\"CircleCI\" src=\"https://circleci.com/gh/kasa-network/koa-http-client.svg?style=shield\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/kasa-network/koa-http-client\"\u003e\n    \u003cimg src=\"https://coveralls.io/repos/github/kasa-network/koa-http-client/badge.svg\" alt='Coverage Status' /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@kasa/koa-http-client\"\u003e\n    \u003cimg alt=\"npm version\" src=\"https://img.shields.io/npm/v/@kasa/koa-http-client.svg\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://david-dm.org/kasa-network/koa-http-client\"\u003e\n    \u003cimg alt=\"npm\" src=\"https://img.shields.io/david/kasa-network/koa-http-client.svg?style=flat-square\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://opensource.org/licenses/mit-license.php\"\u003e\n    \u003cimg alt=\"MIT Licence\" src=\"https://badges.frapsoft.com/os/mit/mit.svg?v=103\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/ellerbrock/open-source-badge/\"\u003e\n    \u003cimg alt=\"Open Source Love\" src=\"https://badges.frapsoft.com/os/v1/open-source.svg?v=103\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\nCommunication between microservices must be efficient. With lots of microservices to complete a single request(transaction) successfully, each communication should have a context informations like the request id, content language, or something else. **Koa HTTP Client** will help inter-service communication with automatically attached context informations.\n\n## Installation\n\n```bash\n# Using NPM\n$ npm install --save @kasa/koa-http-client\n# Using Yarn\n$ yarn add @kasa/koa-http-client\n```\n\n\n### Dependencies\n\n- [**Koa**](https://github.com/koajs/koa) 2.0+\n- [**Node.js**](https://nodejs.org) 8.0.0+\n\n\n## Usage\n\nUse `koa-http-client` as a middleware for a [koa](https://github.com/koajs/koa) app.\n\n```node\nconst Koa = require('koa');\nconst requestId = require('@kasa/koa-http-client');\nconst httpClient = require('@kasa/koa-http-client');\nconst app = new Koa();\n\napp.use(requestId());\napp.use(httpClient({\n  retry: 3\n}));\napp.use(async ctx =\u003e {\n  const userService = ctx.http.extend({\n    baseUrl: 'http://user.company.com:8080/'\n  });\n\n  let user;\n  try {\n    const { body } = await userService.get('/users/john');\n    user = body.user;\n  } catch (err) {\n    // Do something with error (HTTP status code 4xx or 5xx)\n  }\n  // Do something with user data\n});\n\napp.listen(3000);\n```\n\n\n## API\n\n### Creating an middleware\n\nYou can create a new http client middleware by passing the relevant options to `httpClient`;\n\n```node\nconst middleware = httpClient({\n  forwardedHeaders: ['Accept-Language'],\n  userAgent: 'user-service/0.1.0',\n  requestIdHeader: 'X-Service-Request-Id',\n  timeout: 20 * 1000,\n  retry: 3,\n});\n```\n\n### Middleware Configuration\n\nThese are the available config options for the middleware. All is optional. The middleware attachs HTTP client with the context for each request.\n\n```node\n{\n  // HTTP headers to forward from Koa `ctx`\n  forwardedHeaders: ['Accept-Language', 'Authorization'],\n\n  // Client name to set `User-Agent` header\n  userAgent: 'user-service/0.1.0',\n\n  // HTTP header to get/set the request id\n  requestIdHeader: 'X-Service-Request-Id',\n\n  // Milliseconds to wait for the server to end the response before aborting the request\n  timeout: 20 * 1000,\n\n  // Count to retry on the request errors\n  retry: 3,\n}\n```\n\n\n## Credits\n\n* [sindresorhus/got](https://github.com/sindresorhus/got): `koa-http-client` was developed based on `got`. `koa-http-client` utilizes `got.extend` feature well!\n\n\n## Contributing\n\n#### Bug Reports \u0026 Feature Requests\n\nPlease use the [issue tracker](https://github.com/kasa-network/koa-http-client/issues) to report any bugs or ask feature requests.\n\n\n## License\n\nProvided under the terms of the [MIT License](https://github.com/kasa-network/koa-http-client/blob/master/LICENSE).\n\nCopyright © 2019, [Kasa](http://www.kasa.network).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkasa-network%2Fkoa-http-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkasa-network%2Fkoa-http-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkasa-network%2Fkoa-http-client/lists"}