{"id":30495436,"url":"https://github.com/payu/requestxn","last_synced_at":"2025-08-25T00:16:40.271Z","repository":{"id":42718962,"uuid":"116560816","full_name":"PayU/requestxn","owner":"PayU","description":"request-promise wrapper with retries","archived":false,"fork":false,"pushed_at":"2023-01-08T03:42:10.000Z","size":1078,"stargazers_count":4,"open_issues_count":2,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-20T15:03:45.074Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PayU.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-01-07T11:45:59.000Z","updated_at":"2022-01-20T08:25:45.000Z","dependencies_parsed_at":"2023-02-08T04:45:30.119Z","dependency_job_id":null,"html_url":"https://github.com/PayU/requestxn","commit_stats":null,"previous_names":["zooz/requestxn","kobik/requestxn"],"tags_count":24,"template":false,"template_full_name":null,"purl":"pkg:github/PayU/requestxn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PayU%2Frequestxn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PayU%2Frequestxn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PayU%2Frequestxn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PayU%2Frequestxn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PayU","download_url":"https://codeload.github.com/PayU/requestxn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PayU%2Frequestxn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271983819,"owners_count":24853810,"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","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-08-25T00:16:36.293Z","updated_at":"2025-08-25T00:16:40.253Z","avatar_url":"https://github.com/PayU.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM Version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n\u003c!-- [![Maintainability][codeclimate-maintainability-image]][codeclimate-maintainability-url] --\u003e\n\u003c!-- [![Test Coverage][codeclimate-coverage-image]][codeclimate-coverage-url] --\u003e\n\n# requestXn\nWraps request-promise with a retry handler, in order to provide an easy way to send requests with retries and promises.\n\n[![NPM](https://nodei.co/npm/requestxn.png?downloads=true\u0026downloadRank=true\u0026stars=true)][npm-stats]\n\n- [Options](#options)\n  - [max](#max)\n  - [retryOn5xx](#retryon5xx)\n  - [rejectOn5xx](#rejecton5xx)\n  - [retryStrategy](#retrystrategy)\n  - [backoffBase](#backoffbase)\n  - [backoffExponent](#backoffexponent)\n  - [onSuccess](#onsuccess)\n  - [onError](#onerror)\n- [Example](#example)\n\n## Options\n\nrequestXn supports all [request-promise-native](https://github.com/request/request-promise-native) functionality, so you can pass all options as you would pass them to the original package\n\nIn addition to the original *request-promise* options, the following extra options are available\n\n### max\n\nMaximum number of attempts. Default: 1\n\nIf you would like requestXn to retry on a network error, set this options to a value above 1.\n\nThis handles all non-HTTP errors including ENOTFOUND, ECONNRESET, ECONNREFUSED, and ETIMEOUT. \n\n```js\nmax: 1\n```\n\n### retryOn5xx\n\nRetry on 5xx status codes. Default: false\n\nMake requestXn also retry in case of 5xx status codes.\n\n```js\nretryOn5xx: true\n```\n\n### rejectOn5xx\n\nReject when getting 5xx status code and simple=false. Default: false\n\nBy default, requestXn would resolve with the response when simple=false.\n\nBy setting this option to true, requestXn behavior is changed to reject on such cases.\n\n```js\nrejectOn5xx: true\n```\n\n### retryStrategy\n\nCustom retry logic function. Receives a response object and returns a boolean.\n\n```js\n// Retry is HTTP status is \"Too many requests\" or a server error.\nretryStrategy: res =\u003e res.statusCode === 429 || res.statusCode \u003e= 500;\n\n```\n\n### backoffBase\n\nInitial backoff duration in ms. Default: 100\n\n```js\nbackoffBase: 100\n```\n\n### backoffExponent\n\nExponent to increase backoff on each attempt. Default: 1.1\n\n```js\nbackoffExponent: 1.1\n```\n\n### onSuccess\n\nFunction to be executed on success\nNew in v3.0.0: Support async functions\n\n```js\nonSuccess: function (options, response, attempts) {\n    // do something on success\n}\n```\n\n### onError\n\nFunction to be executed on error\nNew in v3.0.0: Support async functions\n\n```js\nonError: function (options, error, attempts) {\n  // do something on error\n}\n```\n\n### Example\n\n```js\nconst request = require('requestxn');\n\nconst options = {\n  url: 'http://www.site-with-issues.com',\n  body: {/* body */},\n  json: true,\n  max: 3,\n  backoffBase: 500,\n  backoffExponent: 1.3,\n  retryOn5xx: true,\n  retryStrategy: function(response) {\n    return response.statusCode === 500 \u0026\u0026 response.body.match(/Temporary error/);\n  },\n  onError: function(options, error, attempts) {\n    console.error(`- Request to ${options.uri} failed on the ${attempts} attempt with error ${error.message}`);\n  },\n  onSuccess: function(options, response, attempts) {\n    console.info(`- Got status-code ${response.statusCode} on request to ${request.uri} after ${attempts}`);\n  }\n}\n```\n\n#### Result\n\n```js\n\u003e request.post(options).then()...\n- \"Request to http://www.site-with-issues.com failed on the 1 attempt with RequestError: Error: getaddrinfo ENOTFOUND www.site-with-issues.com www.site-with-issues.com:80\"\n- \"Request to http://www.site-with-issues.com failed on the 2 attempt with RequestError: Error: getaddrinfo ENOTFOUND www.site-with-issues.com www.site-with-issues.com:80\"\n- \"Got status-code 200 on request to http://www.site-with-issues.com\"\n```\n\n#### Usage with defaults\n\n```js\nconst request = require('requestxn');\n\nconst requestWithDefaults = request.defaults({\n  json: true,\n  max: 3,\n  backoffBase: 500,\n  retryOn5xx: true,\n  retryStrategy: function(response) {\n    return response.statusCode === 500 \u0026\u0026 response.body.match(/Temporary error/);\n  },\n  onError: function(request, error, errorCount) {\n    console.error(`- Request to ${request.url} failed on the ${retries} attempt with error ${error.message}`);\n  },\n  onSuccess: function(request, response) {\n    console.info(`- Got status-code ${response.statusCode} on request to ${request.url}`);\n  }\n});\n\nrequestWithDefaults.get('http://www.site-with-issues.com').then...\n```\n\n[npm-image]: https://img.shields.io/npm/v/requestxn.svg?style=flat\n[npm-url]: https://npmjs.org/package/requestxn\n[travis-image]: https://travis-ci.org/Zooz/requestxn.svg?branch=master\n[travis-url]: https://travis-ci.org/Zooz/requestxn\n[coveralls-image]: https://coveralls.io/repos/github/Zooz/requestxn/badge.svg?branch=master\n[coveralls-url]: https://coveralls.io/repos/github/Zooz/requestxn/badge.svg?branch=master\n[downloads-image]: http://img.shields.io/npm/dm/requestxn.svg?style=flat\n[downloads-url]: https://npmjs.org/package/requestxn\n[npm-stats]: https://nodei.co/npm/requestxn/\n[snyk-image]: https://snyk.io/test/github/Zooz/api-schema-validator/badge.svg?targetFile=package.json\n[snyk-url]: https://snyk.io/test/github/Zooz/api-schema-validator?targetFile=package.json","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpayu%2Frequestxn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpayu%2Frequestxn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpayu%2Frequestxn/lists"}