{"id":16111761,"url":"https://github.com/cliffano/bagofrequest","last_synced_at":"2025-06-11T22:09:13.002Z","repository":{"id":8713715,"uuid":"10382700","full_name":"cliffano/bagofrequest","owner":"cliffano","description":"A bag-of-holding containing request utility functions","archived":false,"fork":false,"pushed_at":"2022-10-11T09:30:15.000Z","size":563,"stargazers_count":1,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-24T17:49:52.875Z","etag":null,"topics":["http","nodejs","request"],"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/cliffano.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":"2013-05-30T12:55:28.000Z","updated_at":"2024-08-25T00:26:14.000Z","dependencies_parsed_at":"2023-01-11T17:27:21.283Z","dependency_job_id":null,"html_url":"https://github.com/cliffano/bagofrequest","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/cliffano/bagofrequest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cliffano%2Fbagofrequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cliffano%2Fbagofrequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cliffano%2Fbagofrequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cliffano%2Fbagofrequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cliffano","download_url":"https://codeload.github.com/cliffano/bagofrequest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cliffano%2Fbagofrequest/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259353144,"owners_count":22844749,"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","nodejs","request"],"created_at":"2024-10-09T19:45:25.704Z","updated_at":"2025-06-11T22:09:12.973Z","avatar_url":"https://github.com/cliffano.png","language":"JavaScript","readme":"\u003cimg align=\"right\" src=\"https://raw.github.com/cliffano/bagofrequest/master/avatar.jpg\" alt=\"Avatar\"/\u003e\n\n[![Build Status](https://img.shields.io/travis/cliffano/bagofrequest.svg)](http://travis-ci.org/cliffano/bagofrequest)\n[![Dependencies Status](https://img.shields.io/david/cliffano/bagofrequest.svg)](http://david-dm.org/cliffano/bagofrequest)\n[![Coverage Status](https://img.shields.io/coveralls/cliffano/bagofrequest.svg)](https://coveralls.io/r/cliffano/bagofrequest?branch=master)\n[![Published Version](https://img.shields.io/npm/v/bagofrequest.svg)](http://www.npmjs.com/package/bagofrequest)\n\u003cbr/\u003e\n[![npm Badge](https://nodei.co/npm/bagofrequest.png)](http://npmjs.org/package/bagofrequest)\n\nBag Of Request\n--------------\nBag Of Request contains request utility functions.\n\nbagofrequest#request\n\nSend http request using [mikeal/request](http://github.com/mikeal/request), with the following additional features:\n\n* status code-based response handlers registration\n* wildcard status code support (e.g. 2xx, 50x)\n* unexpected status code error handling with request body included in message\n* request retry with increasing delay and maximum retries\n* proxy setting based on env vars http_proxy, HTTP_PROXY, https_proxy, HTTPS_PROXY\n* proxy exclusion for localhost and 127.0.0.1\n* request timeout of 30 seconds\n* follow redirects\n* accepts self-signed SSL certificates\n* all of the above defaults can be overridden\n\nbagofrequest#proxy\n\nProxy retrieval based on URL and environment variables:\n\n* if URL uses http, then sets proxy to http_proxy or HTTP_PROXY\n* if URL uses https, then sets proxy to htps_proxy or HTTPS_PROXY, otherwise fallback to http_proxy or HTTP_PROXY\n* if URL does not have a protocol, assume http protocol\n* if URL is not provided, then set proxy to http_proxy or HTTP_PROXY, otherwise fallback to https_proxy or HTTPS_PROXY\n* proxy will be ignored if host is on no_proxy or NO_PROXY when provided, otherwise ignore 127.0.0.1 and localhost\n\nInstallation\n------------\n\n    npm install bagofrequest\n\nor as a dependency in package.json file:\n\n    \"dependencies\": {\n      \"bagofrequest\": \"x.y.z\"\n    }\n\nUsage\n-----\n\n    var bag = require('bagofrequest');\n\nRequest:\n\n    // send http get request with query strings, timeout, and specified status code-based handlers\n    bag.request('get', 'http://somehost', {\n        queryStrings: {\n          param1: 'value1',\n          param2: 'value2'\n        },\n        timeout: 30000,\n        handlers: {\n          '2xx': function (result, cb) {\n            cb(null, result.somedata);\n          },\n          404: function (result, cb) {\n            cb(new Error('Item ' + result.itemId + ' cannot be found'));\n          }\n        }\n      },\n      function (err, result) {\n        // response with unexpected status code (no registered handler) will be passed as error\n      });\n\n    // send http post request\n    bag.request('post', 'http://somehost', {\n        headers: {\n          'content-type': 'application/json'\n        },\n        json: {\n          prop1: 'value1',\n          prop2: 'value2'\n        }\n      },\n      function (err, result) {\n      });\n\n    // send request with options to override any bagofrequest defaults (will be passed to mikeal/request)\n    bag.request('get', 'http://somehost', {\n        requestOpts: {\n          foo: 'bar'\n        }\n      },\n      function (err, result) {\n      });\n\n    // send request with retry settings\n    bag.request('get', 'http://somehost', {\n        retry: {\n          errorCodes: true, // retry on any error\n          statusCodes: [404, 503], // retry when response status code is 404 or 503\n          scale: 0.5, // increase delay by half on each retry\n          delay: 1000, // wait 1 second before retrying\n          maxRetries: 10 // only retry 10 times at most\n        }\n      },\n      function (err, result) {\n      });\n\n    // send request with custom proxy\n    bag.request('get', 'http://somehost', {\n        proxy: 'http://user:pass@someproxy:1234'\n      },\n      function (err, result) {\n      });\n\nProxy:\n\n    // get proxy based on URL protocol\n    // will return undefined when host is localhost or 127.0.0.1\n    var proxy = bag.proxy('https://somehost');\n\n    // get proxy with custom proxy exclusion\n    var proxy = bag.proxy('http://somelocalhost', {\n      noProxyHosts: ['somelocalhost']\n    });\n\nColophon\n--------\n\n[Developer's Guide](https://cliffano.github.io/developers_guide.html#nodejs)\n\nBuild reports:\n\n* [Code complexity report](https://cliffano.github.io/bagofrequest/complexity/plato/index.html)\n* [Unit tests report](https://cliffano.github.io/bagofrequest/test/buster.out)\n* [Test coverage report](https://cliffano.github.io/bagofrequest/coverage/buster-istanbul/lcov-report/lib/index.html)\n* [Integration tests report](https://cliffano.github.io/bagofrequest/test-integration/buster.out)\n* [API Documentation](https://cliffano.github.io/bagofrequest/doc/dox-foundation/index.html)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcliffano%2Fbagofrequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcliffano%2Fbagofrequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcliffano%2Fbagofrequest/lists"}