{"id":23181402,"url":"https://github.com/andr-ll/reqex","last_synced_at":"2026-03-10T14:03:49.180Z","repository":{"id":194885267,"uuid":"692011429","full_name":"andr-ll/reqex","owner":"andr-ll","description":"Promise based http client with built in retry and JSON validator for response","archived":false,"fork":false,"pushed_at":"2024-08-31T05:53:00.000Z","size":545,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-19T05:05:09.550Z","etag":null,"topics":["http","http-client","httpclient","https-client","nodejs","promise","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/reqex","language":"TypeScript","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/andr-ll.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2023-09-15T11:15:52.000Z","updated_at":"2024-08-31T05:53:04.000Z","dependencies_parsed_at":"2023-09-15T15:41:47.496Z","dependency_job_id":"cb7944de-fcef-4144-92b1-f5e8ecf2c789","html_url":"https://github.com/andr-ll/reqex","commit_stats":null,"previous_names":["andr-ii/reqex"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andr-ll%2Freqex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andr-ll%2Freqex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andr-ll%2Freqex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andr-ll%2Freqex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andr-ll","download_url":"https://codeload.github.com/andr-ll/reqex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230238219,"owners_count":18194988,"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":["http","http-client","httpclient","https-client","nodejs","promise","typescript"],"created_at":"2024-12-18T08:15:41.156Z","updated_at":"2026-03-10T14:03:44.126Z","avatar_url":"https://github.com/andr-ll.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reqex\n\n[![NPM][npm-img]][npm-url]\n[![Build][build-img]][build-url]\n[![Coverage][coverage-img]][coverage-url]\n[![License][license-pic]][license-url]\n[![Downloads][npm-downloads]][npm-url]\n\nPromise based http client with built in retry and JSON validator for response.\n\n## Installation\n\n```bash\nnpm install reqex\n```\n\n## Description\n\n**reqex** - is a simple http(s) client which allows to perform\n`GET`, `POST`, `PUT` and `DELETE` requests.\n\nAlso response will contain **parsed json** and could return it\nwith a type if `validate` method is used.\n\nImplemented for convenience with types, and ability to chain request\nmethods. Also supports `pipe` method for streaming response to writable/duplex stream.\n\n## Usage\n\nImport `reqex` to the TS/JS projects:\n\n```js\n// ESM or TypeScript projects:\nimport reqex from 'reqex';\n\n// CommonJS projects:\nconst { reqex } = require('reqex');\n```\n\n\u003e **Note**\n\u003e\n\u003e All responses for any `Content-Type` will have `body` field of string type.\n\u003e The `json` field will have a parsed JSON object value for all responses which\n\u003e have `Content-Type: application/json` header, and `undefined` value for all other types.\n\n### GET\n\n```ts\nconst response = await reqex.get('http://localhost:3000/user');\n\nconsole.log(response);\n```\n\nExpected output:\n\n\u003c!-- cspell:disable --\u003e\n\n```js\n{\n  status: 200,\n  ok: true,\n  contentLength: 23,\n  headers: {\n    'x-powered-by': 'Express',\n    'content-type': 'application/json; charset=utf-8',\n    'content-length': '23',\n    etag: 'W/\"17-notW5/nnoifrwkOLKeW655Vz8Xg\"',\n    date: 'Fri, 15 Sep 2023 10:38:05 GMT',\n    connection: 'close'\n  },\n  json: { user: { name: 'some user', id: 'some id' } },\n  body: '{\"user\":{\"name\":\"some user\",\"id\":\"some id\"}}'\n}\n```\n\n### POST\n\n```ts\nconst response = await reqex\n  .post('http://localhost:3000/user')\n  .body({ name: 'some new user' });\n\nconsole.log(response);\n```\n\nExpected output:\n\n```js\n{\n  status: 201,\n  ok: true,\n  contentLength: 52,\n  headers: {\n    'x-powered-by': 'Express',\n    'content-type': 'application/json; charset=utf-8',\n    'content-length': '52',\n    etag: 'W/\"34-vZ5QItgbUr7K7/mmx0UbwgRbD+w\"',\n    date: 'Fri, 15 Sep 2023 10:45:34 GMT',\n    connection: 'close'\n  },\n  json: { user: { name: 'some new user', id: 'some new id' } },\n  body: '{\"user\":{\"name\":\"some new user\",\"id\":\"some new id\"}}'\n}\n```\n\n### PUT\n\n```ts\nconst response = await reqex\n  .put('http://localhost:3000/user')\n  .body({ name: 'some updated user' });\n\nconsole.log(response);\n```\n\nExpected output:\n\n```js\n{\n  status: 200,\n  ok: true,\n  contentLength: 60,\n  headers: {\n    'x-powered-by': 'Express',\n    'content-type': 'application/json; charset=utf-8',\n    'content-length': '60',\n    etag: 'W/\"3c-EIJ+q9sLuMYRrdJsituIMyqNoJw\"',\n    date: 'Fri, 15 Sep 2023 10:47:09 GMT',\n    connection: 'close'\n  },\n  json: { user: { name: 'some updated user', id: 'some updated id' } },\n  body: '{\"user\":{\"name\":\"some updated user\",\"id\":\"some updated id\"}}'\n}\n```\n\n### DELETE\n\n```ts\nconst response = await reqex\n  .delete('http://localhost:3000/user')\n  .body({ name: 'some user' });\n\nconsole.log(response);\n```\n\nExpected output:\n\n```js\n{\n  status: 204,\n  ok: true,\n  contentLength: 0,\n  headers: {\n    'x-powered-by': 'Express',\n    date: 'Fri, 15 Sep 2023 10:48:00 GMT',\n    connection: 'close'\n  },\n  json: undefined,\n  body: ''\n}\n```\n\n### Retry\n\n\u003e **Note**\n\u003e\n\u003e If `retry` method was called - `pipe` method will be disregarded.\n\n**Does not mean to be used for 400+ status codes, but for connection errors and etc.**\nIf troubles with API for performing requests to are possible - `retry`\nmethod can handle such requests and automatically perform new one.\n\nBy default retries to do request in 10 seconds. Max interval time can be 60 seconds, and max amount\nof attempts - 15 times. If bigger value is passed - max value will be set.\n\nFollowing example will perform up to 3 additional requests, if main request has failed:\n\n```ts\nconst response = await reqex\n  .get('http://localhost:3000/possible-unavailable')\n  .retry({ attempts: 3 });\n```\n\nAlso, next request time can be specified (example - 25 seconds), and log can be added:\n\n```ts\nconst response = await reqex\n  .get('http://localhost:3000/possible-unavailable')\n  .retry({ attempts: 3, interval: 25, logOnRetry: true });\n```\n\n### Pipe\n\n\u003e **Note**\n\u003e\n\u003e If `retry` method was called - `pipe` method will be disregarded.\n\nAllows to pipe response to any `writable`/`duplex` stream. Also returns response as\n`reqex.get()` request:\n\n```ts\nconst stream = fs.createWriteStream('out.json');\n\nconst response = await reqex.get('http://localhost:3000/users').pipe(stream);\n```\n\n### VALIDATE RESPONSE DATA\n\nThe [vator](https://github.com/andr-ii/vator) library is used for validation.\n\n`.validate()` method is designed to assert data is matches provided schema.\nIn case of wrong type - error will be thrown.\n\n```ts\nimport { v } from 'reqex'\n\nconst { json } = await reqex\n  .get('http://localhost:3000/user')\n  .validate({\n    name: v.string;\n    id: v.number;\n  });\n\nconst { name, id } = json;\n\nconsole.log(`The \"name\" field has type \"${typeof name}\" and value \"${name}\"`);\nconsole.log(`The \"id\" field has type \"${typeof id}\" and value \"${id}\"`);\n```\n\nExpected output:\n\n```log\nThe \"name\" field has type \"string\" and value \"some user\"\nThe \"id\" field has type \"number\" and value \"123\"\n```\n\n### NOT JSON CONTENT-TYPE\n\n```ts\nconst response = await reqex\n  .get('http://localhost:3000/')\n  .headers({ 'content-type': 'text/html' });\n\nconsole.log(response);\n```\n\nExpected output:\n\n```js\n{\n  status: 200,\n  ok: true,\n  contentLength: 20,\n  headers: {\n    'x-powered-by': 'Express',\n    'content-type': 'text/html; charset=utf-8',\n    'content-length': '20',\n    etag: 'W/\"14-XVEfTf8cEMbur8HQBK5MH4vJQ7U\"',\n    date: 'Fri, 15 Sep 2023 10:52:59 GMT',\n    connection: 'close'\n  },\n  json: undefined,\n  body: '\u003ch1\u003eHello reqex!\u003c/h1\u003e'\n}\n```\n\n### 400+ status code responses\n\nLets pretend your server responds with `json` content-type for `404 Not Found` cases:\n\n```ts\nconst response = await reqex.get('http://localhost:3000/not-found');\n\nconsole.log(response);\n```\n\nExpected output:\n\n```js\n{\n  status: 404,\n  ok: false,\n  contentLength: 23,\n  headers: {\n    'x-powered-by': 'Express',\n    'content-type': 'application/json; charset=utf-8',\n    'content-length': '23',\n    etag: 'W/\"17-SuRA/yvUWUo8rK6x7dKURLeBo+0\"',\n    date: 'Fri, 15 Sep 2023 11:04:07 GMT',\n    connection: 'close'\n  },\n  json: { message: 'Not Found' },\n  body: '{\"message\":\"Not Found\"}'\n}\n```\n\n[npm-img]: https://img.shields.io/npm/v/reqex.svg?logo=npm\n[npm-url]: https://www.npmjs.com/package/reqex\n[npm-downloads]: https://img.shields.io/npm/dt/reqex?logo=Hack%20The%20Box\u0026logoColor=green\u0026label=downloads\n[build-img]: https://img.shields.io/github/actions/workflow/status/andr-ii/reqex/build.yml?logo=github\n[build-url]: https://github.com/andr-ii/reqex/actions/workflows/build.yml\n[coverage-img]: https://img.shields.io/coverallsCoverage/github/andr-ii/reqex?label=coverage\u0026logo=jest\n[coverage-url]: https://coveralls.io/github/andr-ii/reqex?branch=master\n[license-pic]: https://img.shields.io/github/license/andr-ii/reqex?color=blue\u0026label=%C2%A9%20license\n[license-url]: https://github.com/andr-ii/reqex/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandr-ll%2Freqex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandr-ll%2Freqex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandr-ll%2Freqex/lists"}