{"id":21540016,"url":"https://github.com/robinpowered/react-native-fetch-polyfill","last_synced_at":"2025-05-06T21:28:53.639Z","repository":{"id":57336957,"uuid":"85230374","full_name":"robinpowered/react-native-fetch-polyfill","owner":"robinpowered","description":"Exposes options to React Native's XMLHttpRequest that are not accessible by `whatwg-fetch`","archived":false,"fork":false,"pushed_at":"2018-08-06T14:16:15.000Z","size":11,"stargazers_count":72,"open_issues_count":5,"forks_count":23,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-25T01:02:48.656Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robinpowered.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-16T18:44:10.000Z","updated_at":"2024-12-04T12:20:19.000Z","dependencies_parsed_at":"2022-09-12T09:51:39.510Z","dependency_job_id":null,"html_url":"https://github.com/robinpowered/react-native-fetch-polyfill","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinpowered%2Freact-native-fetch-polyfill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinpowered%2Freact-native-fetch-polyfill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinpowered%2Freact-native-fetch-polyfill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinpowered%2Freact-native-fetch-polyfill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robinpowered","download_url":"https://codeload.github.com/robinpowered/react-native-fetch-polyfill/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252590572,"owners_count":21772936,"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":[],"created_at":"2024-11-24T04:17:01.290Z","updated_at":"2025-05-06T21:28:53.603Z","avatar_url":"https://github.com/robinpowered.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"A polyfill for React Native's `whatwg-fetch`'s mirror.\n\n### The polyfill\n\nThis adds support for `timeout` as one of the `fetch` options.\n\n```js\nimport fetch from 'react-native-fetch-polyfill';\n\nfetch(url, {timeout: 30 * 1000})\n  .then(response =\u003e {\n    // a successful response\n  })\n  .catch(error =\u003e {\n    // an error when the request fails, such as during a timeout\n  })\n```\n\nReact Native's `XMLHttpRequest` interface [exposes a timeout property sent to the `RCTNetworking` module](https://github.com/facebook/react-native/blob/v0.42.1/Libraries/Network/XMLHttpRequest.js#L500), as well as an [abort method](https://github.com/facebook/react-native/blob/v0.42.1/Libraries/Network/XMLHttpRequest.js#L505-L520). `fetch` does not expose access to this by default, this polyfill allows specifying a `timeout` within the options.\n\nThis value [attached to `NSMutableURLRequest`](https://github.com/facebook/react-native/blob/v0.42.1/Libraries/Network/RCTNetworking.mm#L232), where the native networking layer will enforce the timeout rule.\n\nThe result of the timeout being reached will result in a promise [rejected with a `TypeError('Network rqeuest failed')](https://github.com/github/fetch/blob/v1.1.1/fetch.js#L445).\n\n\n### What is fetch?\n\nFetch is a networking abstraction above [`XMLHttpRequest`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest). It reflects the [WHATWG fetch specification](https://fetch.spec.whatwg.org/) and can be found in [whatwg/fetch](https://github.com/whatwg/fetch). It is the networking library [used in React Native](https://facebook.github.io/react-native/docs/network.html#using-fetch).\n\n### Why a polyfill?\n\nFetch has two challenges:\n- It cannot be externally aborted (https://github.com/whatwg/fetch/issues/27 and https://github.com/whatwg/fetch/issues/447)\n- It does not support `timeout`(https://github.com/facebook/react-native/issues/2394, https://github.com/facebook/react-native/issues/2556, https://github.com/whatwg/fetch/issues/20, https://github.com/github/fetch/issues/175)\n\nWhy are these not supported? As a `fetch` maintainer points out in https://github.com/github/fetch/pull/68#issuecomment-70103306, the spec does not describe a standard for this behavior.\n\n### How is the polyfill maintained?\n\nThe polyfill picks out specific pieces of [whatwg/fetch](https://github.com/whatwg/fetch) required to apply the patch.\n\nThe tagged version of the polyfill corresponds to the version of `fetch` that it patches.\n\nWhen new versions of `fetch` are released, the polyfill will be updated and tagged.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinpowered%2Freact-native-fetch-polyfill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobinpowered%2Freact-native-fetch-polyfill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinpowered%2Freact-native-fetch-polyfill/lists"}