{"id":17066479,"url":"https://github.com/mouvedia/cb-fetch","last_synced_at":"2025-04-12T18:50:43.920Z","repository":{"id":57195140,"uuid":"46764641","full_name":"Mouvedia/cb-fetch","owner":"Mouvedia","description":"🔥 Cross-Browser HTTP client","archived":false,"fork":false,"pushed_at":"2020-01-20T13:51:56.000Z","size":202,"stargazers_count":13,"open_issues_count":15,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T17:24:41.027Z","etag":null,"topics":["ajax","cross-browser","fetch","fluent-interface","forward-compatible","umd","xdr","xhr"],"latest_commit_sha":null,"homepage":"https://npm.im/cb-fetch","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/Mouvedia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":"FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":"npm/cb-fetch","community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2015-11-24T03:31:35.000Z","updated_at":"2024-08-01T14:00:07.000Z","dependencies_parsed_at":"2022-09-11T06:51:30.165Z","dependency_job_id":null,"html_url":"https://github.com/Mouvedia/cb-fetch","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mouvedia%2Fcb-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mouvedia%2Fcb-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mouvedia%2Fcb-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mouvedia%2Fcb-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mouvedia","download_url":"https://codeload.github.com/Mouvedia/cb-fetch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618222,"owners_count":21134199,"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":["ajax","cross-browser","fetch","fluent-interface","forward-compatible","umd","xdr","xhr"],"created_at":"2024-10-14T11:07:01.293Z","updated_at":"2025-04-12T18:50:43.898Z","avatar_url":"https://github.com/Mouvedia.png","language":"JavaScript","funding_links":["https://tidelift.com/funding/github/npm/cb-fetch"],"categories":[],"sub_categories":[],"readme":"![min+gzip size](https://img.shields.io/bundlephobia/minzip/cb-fetch.svg)\n![min size](https://img.shields.io/bundlephobia/min/cb-fetch.svg)\n![Flow](https://badgen.net/badge/_/≥0.37.0/3F6EFB?icon=flow\u0026label)\n![TypeScript](https://badgen.net/badge/_/≥2.3.0/1E7ACC?icon=typescript\u0026label)\n\u003ca href=\"http://www.npmjs.com/package/cb-fetch\"\u003e\n  \u003cimg alt=\"npm version\" align=\"right\" src=\"https://badge.fury.io/js/cb-fetch.svg\" /\u003e\n\u003c/a\u003e\u003cbr/\u003e\n\u003ca href=\"https://libraries.io/subscribe/1164538\"\u003e\n  \u003cimg alt=\"libraries.io\" align=\"right\" src=\"https://badgen.net/badge/_/subscribe/50AB50?icon=libraries\u0026label\" /\u003e\n\u003c/a\u003e\n\n# cb-fetch\n\nA truly **c**ross-**b**rowser and forward-compatible library to do asynchronous HTTP requests that follows the **c**all**b**ack pattern.\n\n## Table of Contents\n\n- [Usage](#usage)\n  - [Installation](#installation)\n  - [Importation](#importation)\n  - [Examples](#examples)\n- [Support](#support)\n- [Methods](#methods)\n- [Properties](#properties)\n- [Gotchas](#gotchas)\n- [License](#license)\n\n## Usage\n\n### Installation\n\n#### npm\n\n~~~sh\nnpm install --save cb-fetch\n~~~\n\n#### yarn\n\n~~~sh\nyarn add cb-fetch\n~~~\n\n#### jspm\n\n~~~sh\njspm install cb-fetch\n~~~\n\n#### bower\n\n~~~sh\nbower install --save cb-fetch\n~~~\n\n#### jsDelivr\n\n~~~xml\n\u003cscript src=\"//cdn.jsdelivr.net/combine/npm/@string/isstring/isString.min.js,npm/cb-fetch/index.min.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n~~~\n\n### Importation\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cabbr title=\"Asynchronous Module Definition\"\u003eAMD\u003c/abbr\u003e\u003c/summary\u003e\n  \u003cpre\u003e\u003ccode\u003e\n  define(function (require) {\n    var request = require('cb-fetch');\n  });\n  \u003c/code\u003e\u003c/pre\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cabbr title=\"CommonJS\"\u003eCJS\u003c/abbr\u003e\u003c/summary\u003e\n  \u003ch4\u003estandard compliant\u003c/h4\u003e\n  \u003cpre\u003e\u003ccode\u003e\n  var request = require('cb-fetch')['default'];\n  \u003c/code\u003e\u003c/pre\u003e\n\n  \u003ch4\u003eNode.js compatible\u003c/h4\u003e\n  \u003cpre\u003e\u003ccode\u003e\n  var request = require('cb-fetch');\n  \u003c/code\u003e\u003c/pre\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cabbr title=\"Yahoo! User Interface\"\u003eYUI\u003c/abbr\u003e\u003c/summary\u003e\n  \u003cpre\u003e\u003ccode\u003e\n  YUI({\n    modules: { 'is-string': 'path/to/@string/isstring.js' }\n  }).use('is-string', 'cb-fetch', function (Y) {\n    var request = Y['default'];\n  });\n  \u003c/code\u003e\u003c/pre\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003cabbr title=\"TypeScript\"\u003eTS\u003c/abbr\u003e\u003c/summary\u003e\n  \u003cpre\u003e\u003ccode\u003e\n  import request = require('cb-fetch');\n  \u003c/code\u003e\u003c/pre\u003e\n\u003c/details\u003e\n\n\u003cdetails open=\"open\"\u003e\n  \u003csummary\u003eGlobal Namespace\u003c/summary\u003e\n  \u003cp\u003eIf none of the previously listed module registration methods are supported, a global variable named \u003ccode\u003erequest\u003c/code\u003e will be exposed.\u003c/p\u003e\n\u003c/details\u003e\n\n### Examples\n\n~~~js\n// here's your typical request\nrequest('http://www.example.com?key1=value1\u0026key2=value2')\n  .done(response =\u003e { /* … */ });\n\n// taking a comprehensive approach is encouraged though\nrequest()\n  .get('http://www.example.com')\n  .query('key1=value1\u0026key2=value2')\n  .done(onSuccessCallback, onErrorCallback);\n\n// passing an object offers options not available otherwise\nlet abort = request({\n  url:          new URL('http://www.example.com'),\n  parameters:   new URLSearchParams('_csrf=TOKEN'),\n  mode:         'cors',\n  credentials:  'include',\n  responseType: 'json'\n}).get('/segment')\n  .query({ foo: ['bar', 'qux'] })\n  .pass('Content-Type', 'application/json')\n  .hook('download', e =\u003e { /* … */ })\n  .done({\n    success: onSuccessCallback,\n    error:   onErrorCallback,\n    abort:   onAbortCallback\n  });\n\n// forcefully aborts the request\nabort();\n~~~\n\n## Support\n\n- [x] `fetch`\n- [x] `XMLHttpRequest`\n- [x] `XDomainRequest`\n- [x] Universal Module Definition\n- [x] WebDAV\n- [x] TypeScript\n- [x] Flow\n\n## Methods\n\n### get / head / delete / post / patch / put\n\n~~~\n(Options.url?) =\u003e Object\n~~~\n\n### query\n\n~~~\n(Options.parameters?) =\u003e Object\n~~~\n\n### send\n\n~~~\n(Options.body?) =\u003e Object\n~~~\n\n### hook\n\n#### loadstart\n\n~~~\n('loadstart', () =\u003e Boolean | Void) =\u003e Object\n~~~\n\n\u003ch4\u003edownload\u003cimg align=\"right\" src=\"https://badges.herokuapp.com/browsers?firefox=%E2%89%A50.9.3\u0026opera=%E2%89%A512\u0026iexplore=%E2%89%A58\u0026googlechrome=%E2%89%A51\u0026safari=%E2%89%A54\u0026labels=none\u0026line=true\" /\u003e\u003c/h4\u003e\n\n~~~\n('download', Object =\u003e Any) =\u003e Object\n~~~\n\n#### loadend\n\n~~~\n('loadend', () =\u003e Any) =\u003e Object\n~~~\n\n### pass\n\n~~~\n{\n  (name: String, value: String),\n  (headers: Object | Headers)\n} =\u003e Object\n~~~\n\n~~~js\n  // assigns\n  .pass(new Headers({ key: 'value' }))\n\n  // appends\n  .pass({ key: 'value' })\n\n  // sets\n  .pass('key', 'value')\n~~~\n\n### done\n\n~~~\n{\n  (onSuccess?: Function, onError?: Function),\n  ({\n    success?:  Function,\n    error?:    Function,\n    timeout?:  Function,\n    abort?:    Function\n  })\n} =\u003e () =\u003e Void,\n  throws: TypeError\n~~~\n\n## Properties\n\n### Request Options\n\nProperty     | Default       | Value(s)\n--------     | -------       | --------\nbody         | null          | BufferSource, Blob, Document², FormData, String, URLSearchParams, ReadableStream\ncredentials  | 'same‑origin' | 'include', 'omit'⁶, 'same-origin'\nheaders      | {}            | Object, Headers³\nmethod       | 'GET'         | String\nmode         | 'same‑origin' | 'cors', 'no-cors'¹, 'same-origin'\npassword     | null          | String\nparameters   |               | URLSearchParams, Object, String\nresponseMediaType² |         | String\nresponseType |               | 'text', 'json', 'blob', 'document', 'arraybuffer', 'formdata'¹, 'moz-blob', 'moz-chunked-arraybuffer', 'moz-chunked-text', 'msxml-document'\ntimeout      | 0             | ℕ\nusername     | null          | String\nurl          | location.href | String, URL\nmultipart⁷   | false         | Boolean\ntunneling⁵   | false         | Boolean\nXSLPattern⁴  | false         | Boolean\n\n### Progress Event\n\nProperty         | Type\n--------         | ----\nchunk            | String, ArrayBuffer, Blob, Uint8Array, null\naggregate        | String, ArrayBuffer, Blob, Uint8Array, null\nloaded           | ℕ\ntotal            | ℕ\nlengthComputable | Boolean\n\n### Response\n\nProperty   | Type\n--------   | ----\nbody       | Object, String, Document, ArrayBuffer, Blob, FormData¹, ReadableStream¹, null\nheaders    | Object\ninstance   | XMLHttpRequest, XDomainRequest, Response, AnonXMLHttpRequest\nstatusCode | ℕ\nstatusText | String\nurl        | String\n\n\u003csub\u003e\u003csup\u003e¹ fetch only\u003cbr/\u003e\n² XHR only\u003cbr/\u003e\n³ except Gecko 34–43\u003cbr/\u003e\n⁴ MSXML 3.0 only\u003cbr/\u003e\n⁵ method override\u003cbr/\u003e\n⁶ fetch, Gecko 16+, Presto/2.10.232–2.12.423\u003cbr/\u003e\n⁷ Gecko 1.7β–22\u003c/sup\u003e\u003c/sub\u003e\n\n## Gotchas\n\n### `delete` reserved keyword\n\nIn pre-ES5 environments, the delete method requires the use of the bracket notation.\n\n### Gecko\n\nFor the browsers powered by Gecko 1.9.1–20 to have the exposed response headers\npopulated into the `headers` property, the following conditions must be met:\n\n- `Access-Control-Expose-Headers` response header exposes itself\n- `Access-Control-Expose-Headers` field value is not `*`\n- `mode` set to `cors`\n\n### Trident\n\n#### `XDomainRequest` intrinsic limitations\n\n- only support GET and POST methods\n- cannot set request headers\n- no credentials\n- same scheme restriction\n- the informational and redirection status code classes are considered errors\n- the response's status code and status text are not supplied\n- same-origin requests _also_ require the server to respond with an `Access-Control-Allow-Origin` header of either `*`\nor the exact URL of the requesting document\n\n#### Platform for Privacy Preferences\n\nInternet Explorer’s default settings restrict the use of 3\u003csup\u003erd\u003c/sup\u003e party cookies unless a P3P compact policy\ndeclaration has been included through a custom HTTP response header; hence, the `\"include\"` credentials mode cannot be\nfully honored if a cookie has been deemed unsatisfactory.\n\n## License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FMouvedia%2Fcb-fetch.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FMouvedia%2Fcb-fetch?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmouvedia%2Fcb-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmouvedia%2Fcb-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmouvedia%2Fcb-fetch/lists"}