{"id":13491881,"url":"https://github.com/lquixada/cross-fetch","last_synced_at":"2025-05-14T21:02:20.424Z","repository":{"id":39741297,"uuid":"102216161","full_name":"lquixada/cross-fetch","owner":"lquixada","description":"Universal WHATWG Fetch API for Node, Browsers and React Native.","archived":false,"fork":false,"pushed_at":"2025-04-15T12:40:26.000Z","size":3215,"stargazers_count":1679,"open_issues_count":25,"forks_count":105,"subscribers_count":12,"default_branch":"v4.x","last_synced_at":"2025-05-07T19:47:42.716Z","etag":null,"topics":["cross-fetch","fetch","fetch-api","http","http-client","isomorphic","isomorphic-fetch","node-fetch","spec-compliant","whatwg-fetch"],"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/lquixada.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-09-02T18:36:08.000Z","updated_at":"2025-04-29T04:45:03.000Z","dependencies_parsed_at":"2024-09-26T23:36:25.425Z","dependency_job_id":"b553f2c7-d0ec-4cb4-bc21-82a12de70037","html_url":"https://github.com/lquixada/cross-fetch","commit_stats":{"total_commits":677,"total_committers":20,"mean_commits":33.85,"dds":0.03692762186115217,"last_synced_commit":"5518a175f9db7f3bb99af1c9264b13abf2d61c79"},"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lquixada%2Fcross-fetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lquixada%2Fcross-fetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lquixada%2Fcross-fetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lquixada%2Fcross-fetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lquixada","download_url":"https://codeload.github.com/lquixada/cross-fetch/tar.gz/refs/heads/v4.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253540761,"owners_count":21924535,"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":["cross-fetch","fetch","fetch-api","http","http-client","isomorphic","isomorphic-fetch","node-fetch","spec-compliant","whatwg-fetch"],"created_at":"2024-07-31T19:01:01.104Z","updated_at":"2025-05-14T21:02:20.339Z","avatar_url":"https://github.com/lquixada.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Browser Features","Framework agnostic packages"],"sub_categories":["Async"],"readme":"cross-fetch\u003cbr\u003e\n[![NPM Version](https://img.shields.io/npm/v/cross-fetch.svg?branch=main)](https://www.npmjs.com/package/cross-fetch)\n[![Downloads Per Week](https://img.shields.io/npm/dw/cross-fetch.svg?color=blue)](https://www.npmjs.com/package/cross-fetch)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![CI](https://github.com/lquixada/cross-fetch/actions/workflows/ci.yml/badge.svg)](https://github.com/lquixada/cross-fetch/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/lquixada/cross-fetch/branch/main/graph/badge.svg)](https://codecov.io/gh/lquixada/cross-fetch)\n================\n\nUniversal WHATWG Fetch API for Node, Browsers, Workers and React Native. The scenario that cross-fetch really shines is when the same JavaScript codebase needs to run on different platforms.\n\n- **Platform agnostic**: browsers, Node or React Native\n- **Optional polyfill**: it's up to you if something is going to be added to the global object or not\n- **Simple interface**: no instantiation, no configuration and no extra dependency\n- **WHATWG compliant**: it works the same way wherever your code runs\n- **TypeScript support**: better development experience with types.\n- **Worker support**: works on different types of workers such as Service Workers and CloudFlare Workers\n\n\n* * *\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [Demo \\\u0026 API](#demo--api)\n- [FAQ](#faq)\n    - [Yet another fetch library?](#yet-another-fetch-library)\n    - [Why polyfill might not be a good idea?](#why-polyfill-might-not-be-a-good-idea)\n    - [How does cross-fetch work?](#how-does-cross-fetch-work)\n- [Who's Using It?](#whos-using-it)\n- [Thanks](#thanks)\n- [License](#license)\n- [Author](#author)\n\n* * *\n\n## Install\n\n```sh\nnpm install --save cross-fetch\n```\n\nAs a [ponyfill](https://github.com/sindresorhus/ponyfill) (imports locally):\n\n```javascript\n// Using ES6 modules with Babel or TypeScript\nimport fetch from 'cross-fetch';\n\n// Using CommonJS modules\nconst fetch = require('cross-fetch');\n```\n\nAs a polyfill (installs globally):\n\n```javascript\n// Using ES6 modules\nimport 'cross-fetch/polyfill';\n\n// Using CommonJS modules\nrequire('cross-fetch/polyfill');\n```\n\n\nThe CDN build is also available on unpkg:\n\n```html\n\u003cscript src=\"//unpkg.com/cross-fetch/dist/cross-fetch.js\"\u003e\u003c/script\u003e\n```\n\nThis adds the fetch function to the window object. Note that this is not UMD compatible.\n\n\n* * *\n\n## Usage\n\nWith [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise):\n\n```javascript\nimport fetch from 'cross-fetch';\n// Or just: import 'cross-fetch/polyfill';\n\nfetch('//api.github.com/users/lquixada')\n  .then(res =\u003e {\n    if (res.status \u003e= 400) {\n      throw new Error(\"Bad response from server\");\n    }\n    return res.json();\n  })\n  .then(user =\u003e {\n    console.log(user);\n  })\n  .catch(err =\u003e {\n    console.error(err);\n  });\n```\n\nWith [async/await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function):\n\n```javascript\nimport fetch from 'cross-fetch';\n// Or just: import 'cross-fetch/polyfill';\n\n(async () =\u003e {\n  try {\n    const res = await fetch('//api.github.com/users/lquixada');\n    \n    if (res.status \u003e= 400) {\n      throw new Error(\"Bad response from server\");\n    }\n    \n    const user = await res.json();\n  \n    console.log(user);\n  } catch (err) {\n    console.error(err);\n  }\n})();\n```\n\n## Demo \u0026 API\n\nYou can find a comprehensive doc at [Github's fetch](https://github.github.io/fetch/) page. If you want to play with cross-fetch, check our [**JSFiddle playground**](https://jsfiddle.net/lquixada/3ypqgacp/).\n\n\u003e **Tip**: Run the fiddle on various browsers and with different settings (for instance: cross-domain requests, wrong urls or text requests). Don't forget to open the console in the test suite page and play around.\n\n\n## FAQ\n\n#### Yet another fetch library?\n\nI did a lot of research in order to find a fetch library that could be simple, cross-platform and provide polyfill as an option. There's a plethora of libs out there but none could match those requirements.\n\n#### Why polyfill might not be a good idea?\n\nIn a word? Risk. If the spec changes in the future, it might be problematic to debug. Read more about it on [sindresorhus's ponyfill](https://github.com/sindresorhus/ponyfill#how-are-ponyfills-better-than-polyfills) page. It's up to you if you're fine with it or not.\n\n#### How does cross-fetch work?\n\nJust like isomorphic-fetch, it is just a proxy. If you're in node, it delivers you the [node-fetch](https://github.com/bitinn/node-fetch/) library, if you're in a browser or React Native, it delivers you the github's [whatwg-fetch](https://github.com/github/fetch/). The same strategy applies whether you're using polyfill or ponyfill.\n\n\n## Who's Using It?\n\n|[![The New York Times](./docs/images/logo-nytimes.png)](https://www.nytimes.com/)|[![Apollo GraphQL](./docs/images/logo-apollo.png)](https://github.com/apollographql/apollo-client/)|[![Facebook](./docs/images/logo-facebook.png)](https://github.com/facebook/fbjs/)|[![Swagger](./docs/images/logo-swagger.png)](https://swagger.io/)|[![VulcanJS](./docs/images/logo-vulcanjs.png)](http://vulcanjs.org)|[![graphql-request](./docs/images/logo-graphql-request.png)](https://github.com/prisma/graphql-request)|\n|:---:|:---:|:---:|:---:|:---:|:---:|\n|The New York Times|Apollo GraphQL|Facebook|Swagger|VulcanJS|graphql-request|\n\n\n## Thanks\n\nHeavily inspired by the works of [matthew-andrews](https://github.com/matthew-andrews). Kudos to him!\n\n\n## License\n\ncross-fetch is licensed under the [MIT license](https://github.com/lquixada/cross-fetch/blob/main/LICENSE) © [Leonardo Quixadá](https://twitter.com/lquixada/)\n\n\n## Author\n\n|[![@lquixada](https://avatars0.githubusercontent.com/u/195494?v=4\u0026s=96)](https://github.com/lquixada)|\n|:---:|\n|[@lquixada](http://www.github.com/lquixada)|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flquixada%2Fcross-fetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flquixada%2Fcross-fetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flquixada%2Fcross-fetch/lists"}