# react-native-fetch-polyfill

> A polyfill for React Native's fetch client

Latest version **1.1.3** (published 2018-08-06) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install react-native-fetch-polyfill
pnpm add react-native-fetch-polyfill
yarn add react-native-fetch-polyfill
bun add react-native-fetch-polyfill
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2018-08-06 |
| First published | 2017-05-18 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 73 |
| Maintainers | atticoos |
| Keywords | ReactNative, fetch, timeout |

## Links

- npm: https://www.npmjs.com/package/react-native-fetch-polyfill
- Repository: https://github.com/robinpowered/react-native-fetch-polyfill
- Homepage: https://github.com/robinpowered/react-native-fetch-polyfill#readme
- Issues: https://github.com/robinpowered/react-native-fetch-polyfill/issues
- npm.io page: https://npm.io/package/react-native-fetch-polyfill

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 1.1.3 (latest) — 2018-08-06
- 1.1.2 — 2017-05-18

## README

A polyfill for React Native's `whatwg-fetch`'s mirror.

### The polyfill

This adds support for `timeout` as one of the `fetch` options.

```js
import fetch from 'react-native-fetch-polyfill';

fetch(url, {timeout: 30 * 1000})
  .then(response => {
    // a successful response
  })
  .catch(error => {
    // an error when the request fails, such as during a timeout
  })
```

React 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.

This 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.

The 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).


### What is fetch?

Fetch 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).

### Why a polyfill?

Fetch has two challenges:
- It cannot be externally aborted (https://github.com/whatwg/fetch/issues/27 and https://github.com/whatwg/fetch/issues/447)
- 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)

Why 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.

### How is the polyfill maintained?

The polyfill picks out specific pieces of [whatwg/fetch](https://github.com/whatwg/fetch) required to apply the patch.

The tagged version of the polyfill corresponds to the version of `fetch` that it patches.

When new versions of `fetch` are released, the polyfill will be updated and tagged.

---
_Source: https://npm.io/package/react-native-fetch-polyfill · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
