{"id":17737675,"url":"https://github.com/kshetline/by-request","last_synced_at":"2026-01-21T02:09:31.530Z","repository":{"id":34969135,"uuid":"192773457","full_name":"kshetline/by-request","owner":"kshetline","description":"Simple Node http client for use with promises, async/await.","archived":false,"fork":false,"pushed_at":"2025-10-02T00:31:35.000Z","size":539,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-02T02:39:13.201Z","etag":null,"topics":["async-await","bom","character-encoding","curl","file","http-client","https-client","javascript","json","jsonp","nodejs","promises","typescript","wget"],"latest_commit_sha":null,"homepage":null,"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/kshetline.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-06-19T17:05:44.000Z","updated_at":"2025-10-02T00:29:15.000Z","dependencies_parsed_at":"2024-01-16T12:46:38.298Z","dependency_job_id":"48b91959-5dd5-46ff-b496-6df43923e867","html_url":"https://github.com/kshetline/by-request","commit_stats":{"total_commits":49,"total_committers":2,"mean_commits":24.5,"dds":"0.020408163265306145","last_synced_commit":"f2021e93d09248a5a5429d077a1dd0628ff2b960"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/kshetline/by-request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kshetline%2Fby-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kshetline%2Fby-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kshetline%2Fby-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kshetline%2Fby-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kshetline","download_url":"https://codeload.github.com/kshetline/by-request/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kshetline%2Fby-request/sbom","scorecard":{"id":571321,"data":{"date":"2025-08-11","repo":{"name":"github.com/kshetline/by-request","commit":"8077cc2cb235bd3e9199f145c2f5dfed3912d56e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 0/13 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":9,"reason":"11 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 9","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 24 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":8,"reason":"2 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-xffm-g5w8-qvg7","Warn: Project is vulnerable to: GHSA-76c9-3jph-rj3q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T16:25:51.593Z","repository_id":34969135,"created_at":"2025-08-20T16:25:51.593Z","updated_at":"2025-08-20T16:25:51.593Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28622473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T23:49:58.628Z","status":"online","status_checked_at":"2026-01-21T02:00:08.227Z","response_time":86,"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":["async-await","bom","character-encoding","curl","file","http-client","https-client","javascript","json","jsonp","nodejs","promises","typescript","wget"],"created_at":"2024-10-26T01:42:15.650Z","updated_at":"2026-01-21T02:09:31.524Z","avatar_url":"https://github.com/kshetline.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# by-request\n\n## Simple Node HTTP/HTTPS client for use with promises and async/await\n\nThe **by-request** package provides four ways to retrieve data via HTTP/HTTPS, all of which return `Promise`s, and all of which are suitable for use with `async`/`await`:\n\n* `requestBinary(`...`): Promise\u003cBuffer\u003e`\n* `requestFile(`...`): Promise\u003cnumber\u003e` (_can also output to `Writable` streams instead of files_)\n* `requestJson(`...`): Promise\u003cany\u003e`\n* `requestText(`...`): Promise\u003cstring\u003e`\n\nGET and POST requests are handled, and optional automatic file caching can be used.\n\n[![npm](https://img.shields.io/npm/v/by-request.svg)](https://www.npmjs.com/package/by-request/) [![Coverage Status](https://coveralls.io/repos/github/kshetline/by-request/badge.svg?branch=master)](https://coveralls.io/github/kshetline/by-request) [![npm downloads](https://img.shields.io/npm/dm/by-request.svg)](https://npmjs.org/package/by-request/) ![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/by-request)  ![license](https://img.shields.io/badge/licence-mit-informational)\n\n### Installation\n\n`npm install by-request`\n\n### Examples\n\n```typescript\nconst audio = await requestBinary('https://musicalstuff.net/some_song.mp3');\n```\n\n```typescript\nconst forecast = await requestText('https://forekast.info/forecast/local/', {\n    cacheDir: 'weather-cache/',\n    maxCacheAge: 900000, // 15 minutes\n    params: { city: 'poughkeepsie', state: 'ny', country: 'us' }\n  });\n```\n\n```typescript\nconst options = {progress: (bytesRead, totalBytes) =\u003e {\n  if (totalBytes)\n    console.log((bytesRead / totalBytes * 100).toFixed(1) + '% downloaded');\n  else\n    console.log((bytesRead / 1024).toFixed(1) + 'K downloaded');\n}};\n\nrequestFile('https://tedious.org/2024/07/meeting_minutes.docx', options, 'documents/tldnr/').then(length =\u003e {\n  console.log('Document retrieved, length in bytes: ' + length);\n}).catch(err =\u003e {\n  console.error('Something went wrong: ' + err.message);\n});\n```\n\n```typescript\nlet whereAmI = await requestJson('http://ip-api.com/json/');\n```\n\n```typescript\nlet currentTemperature = parseFloat((await requestText('https://howhotisit.biz/forecast/?zip=02134'))\n      .replace(/.*Current temperature:\\s*([-.0-9]+).*/is, '$1'));\n```\n\nHTTP(S) redirects are automatically handled using [follow-redirects](https://github.com/follow-redirects/follow-redirects), and a wide variety of character encodings are supported using [iconv-lite](https://github.com/ashtuchkin/iconv-lite).\n\nHTTP(S) responses which are compressed using the `gzip`, `deflate` or `br` methods are automatically decompressed. (When using `requestBinary()` or `requestFile()`, this automatic decompression can be disabled.)\n\nURLs can be specified either as strings or via an `ExtendedRequestOptions` object. When a URL is specified as a string, additional options can still be specified via a subsequent `ExtendedRequestOptions` parameter.\n\n`ExtendedRequestOptions` is an extension of the standard Node [`RequestOptions`](https://nodejs.org/api/http.html#http_http_request_options_callback) object. Those options have been extended as follows:\n\n```typescript\ninterface ExtendedRequestOptions extends RequestOptions {\n  autoDecompress?: boolean;\n  body?: Buffer | string; // For POST requests\n  cachePath?: string;\n  dontDecompress?: boolean;\n  dontEndStream?: boolean;\n  followRedirects?: boolean; // follow-redirects\n  forceEncoding?: boolean;\n  ignoreBom?: boolean;\n  json?: any; // For POST requests\n  keepBom?: boolean;\n  maxBodyLength?: number; // follow-redirects\n  maxCacheAge?: number;\n  maxRedirects?: number; // follow-redirects\n  params?: string | Record\u003cstring, string | number | boolean | null\u003e; // For POST requests\n  progress?: (bytesRead: number, totalBytes: number | undefined) =\u003e void;\n  responseInfo?: (info: ResponseInfo) =\u003e void;\n  trackRedirects?: boolean; // follow-redirects\n}\n```\n\nFor the options marked \"follow-redirects\", see the [follow-redirects documentation](https://github.com/follow-redirects/follow-redirects/blob/master/README.md).\n\nThe other options are available as follows:\n\n* `autoDecompress`: If a response has a `Content-Type` of gzip, gzipped, or gunzip, automatically decompress the content rather than returning the compressed data.\n* `body`: If a `body` for a request is provided, the request will be made using the POST method, and the `body` will be sent as part of the request. The `Content-Type` header will automatically be `text/plain; charset=UTF-8` unless you provide an overriding header value.\n* `cachePath`: This is either a file path for where cached data should be stored under a specific file name for the current request, or a directory (indicated using a `'/'` at the end of the path) where cached data will be stored using auto-generated file names.\n* `dontDecompress`: For use with `requestBinary()` and `requestFile()`, set to `true` to prevent automatic decompression of `gzip`, `deflate`, or `br` data.\n* `dontEndStream`: For use with `requestFile()`, this prevents `stream.end()` from automatically being called when `requestFile()` terminates. This option applies to either a stream passed in as an argument (in lieu of a file path), or to the internally created file output stream. If you choose not to end the internally created stream automatically, you should also use the `responseInfo` callback so that you can access that stream to end it later. Errors will always end any internally created stream.\n* `forceEncoding`: For use with `requestText()`, setting this to `true` causes the `encoding` argument passed into the function to override any encoding specified by the retrieved data itself.\n* `ignoreBom`: By default `requestJson()` and `requestText()` look to see if a UTF-7, -8, -16, or -32 BOM [(Byte Order Mark)](https://en.wikipedia.org/wiki/Byte_order_mark) is present as one way of determining content character encoding. Setting `ignoreBom` to `true` allows the BOM to be ignored.\n* `json`: Causes a POST request to be made, either using a `string` value treated as a literal JSON body, or any other type of value which will be stringified to create the POSTed `application/json; charset=UTF-8` body.\n* `keepBom`: If a BOM is detected by `requestJson()` or `requestText()`, it is normally deleted. Set `keepBom` to `true` to preserve the BOM.\n* `maxCacheAge`: When using the `cacheDir` option, this parameter allows you to ignore cached data older than `maxCacheAge` milliseconds.\n* `params`: Causes a POST request to be made, either using a `string` value treated as a literal pre-URL-encoded string of name and values, or a name/value pair object which will be URL-encoded to create the POSTed `application/x-www-form-urlencoded; charset=UTF-8` body.\n* `progress`: As seen in the `requestFile()` example at the beginning of this document, this is an optional callback that provides feedback during the retrieval of large resources, returning the number of bytes read at a particular point in time, and, if known (otherwise `undefined`), the total number of bytes expected.\n* `responseInfo`: This optional callback provides meta-information about the resource which has been retrieved and the retrieval process. The data provided looks like this:\n\n```typescript\ninterface ResponseInfo {\n  bomDetected: boolean;\n  bomRemoved: boolean;\n  cachePath?: string;\n  callback?: string;\n  charset: string;\n  contentEncoding: string;\n  contentLength: number;\n  contentType: string;\n  fromCache?: boolean;\n  stream: Writable;\n}\n```\n\n* `bomDetected`: Whether a BOM was detected.\n* `bomRemoved`: Whether a BOM was removed.\n* `callback`: If JSONP data has been retrieved, this is the name of the callback function.\n* `cachePath`: If the `cachePath` option is used in your request, this will contain the name of the file where data has been cached. If the cache was used rather than making a fresh HTTP/HTTPS request, this value and `fromCache` will be the only feedback received.\n* `charset`: The character encoding ultimately used to interpret text or JSON data. This will be `'binary'` for binary and file operations.\n* `contentEncoding`: The value of the HTTP `Content-Encoding` header.\n* `contentLength`: The total number of bytes read. For compressed data, this is the compressed length, not the expanded length.\n* `contentType`: The value of the HTTP `Content-Type` header.\n* `fromCache`: `true` if content was retrieved from cache.\n* `stream`: When using `requestFile()`, this is either the stream passed into the function, or the stream created for the file path.\n\nNote: If you provide your own `Content-Type` header, only the `body` option is valid for POSTed content (`json` and `params` options will be ignored), and you are responsible for correctly encoding the provided `body`. All requests without using the `body`, `json`, or `params` options use the GET method, rather than POST.\n\n### Functions\n\n#### `requestBinary(`...`)`\n\n```typescript\nasync function requestBinary(urlOrOptions: string | ExtendedRequestOptions,\n                             options?: ExtendedRequestOptions): Promise\u003cBuffer\u003e\n```\n\nGets binary data as a `Buffer`. Apart from decompression (which can be optionally disabled), data is retrieved as sent, with no character encoding transformations performed.\n\n#### `requestFile(`...`)` (or `wget(`...`)`)\n\n```typescript\nasync function requestFile(urlOrOptions: string | ExtendedRequestOptions,\n                           optionsOrPathOrStream?: ExtendedRequestOptions | string | Writable,\n                           pathOrStream?: string | Writable): Promise\u003cnumber\u003e\n```\n\nRetrieves an HTTP(S) resource to save as a file, or to send to a `Writable` output stream. Apart from decompression (which can be optionally disabled), data is retrieved as sent, with no character encoding transformations performed. The function returns the length of the file.\n\nIf a path string is specified that does not end in a slash (`/`), that path is used as the complete file path for saving the retrieved data. If it does end in a slash, it is treated as a directory, and the complete file path is formed by extracting a file name from the end of the URL for the resource.\n\nIf no path (or `Writable` stream) is specified, only a URL, the file name is extracted from the end of the URL, and the file is created in the current working directory.\n\n#### `requestJson(`...`)`\n\n```typescript\nasync function requestJson(urlOrOptions: string | ExtendedRequestOptions,\n                           options?: ExtendedRequestOptions): Promise\u003cany\u003e\n```\n\nGets JSON or JSONP data, returning it as whatever data type is applicable. If JSONP data is detected, the `responseInfo` callback can be used to retrieve the name of the JSONP callback function.\n\nSince JSON is now almost universally encoded using UTF-8, no encoding parameter is provided for this function, and the retrieved data will be decoded by something other than UTF-8 only if the HTTP `Content-Type` header, or a BOM marker, indicate otherwise. Should the odd case arise where you need to force the use of a different encoding, use `requestText()` instead, along with `JSON.parse()`.\n\n#### `requestText(`...`)`\n\n```typescript\nasync function requestText(urlOrOptions: string | ExtendedRequestOptions, encoding?: string): Promise\u003cstring\u003e\n\nasync function requestText(url: string, options: ExtendedRequestOptions, encoding?: string): Promise\u003cstring\u003e\n\nasync function requestText(urlOrOptions: string | ExtendedRequestOptions,\n                           optionsOrEncoding?: ExtendedRequestOptions | string, encoding?: string): Promise\u003cstring\u003e\n```\n\nGets text data and returns it as a string. The character encoding scheme used to decode the text is applied according to the following order of priority:\n\n1. The `encoding` parameter (or `optionsOrEncoding` parameter, as a string value) when the `forceEncoding` option is `true`. This will override any declared encoding based on a BOM, HTTP headers, or text content.\n2. The encoding expressed via a BOM, if present, and if not ignored via the `ignoreBom` option.\n3. The `charset` value, if provided, in the HTTP `Content-Type` header.\n4. The UTF-16 or UTF-32 encoding implied by the pattern of zero and non-zero values in the first four bytes of the HTTP(S) content.\n5. Any content-specified encoding that can be seen by looking within the first 2K of data, interpreting that data as if it were ASCII, and finding declarations such as these:\n\n    `\u003c?xml version=\"1.0\" encoding=\"iso-8859-1\"?\u003e`\n\n    `\u003cmeta charset=\"iso-8859-1\"\u003e`\n\n    `\u003cmeta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"\u003e`\n\n    `@charset \"iso-8859-1\"`\n\n6. The `encoding` parameter (or `optionsOrEncoding` parameter, as a string value) when the `forceEncoding` option is `false` (or not specified).\n7. UTF-8.\n\n### Error handling\n\nWhen using these functions via the returned `Promise`, the `Promise` `catch` method should be used to handle errors. When using `async`/`await`, errors should be caught using `try`/`catch`.\n\nPossible errors include bad HTTP status codes, timeouts and other I/O errors, corrupted or invalid data, unsupported character encodings, and invalid function parameters or options.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkshetline%2Fby-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkshetline%2Fby-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkshetline%2Fby-request/lists"}