# fetch-intercept

> Interceptor library for the native fetch command inspired by angular http intercepts.

Latest version **2.4.0** (published 2021-06-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install fetch-intercept
pnpm add fetch-intercept
yarn add fetch-intercept
bun add fetch-intercept
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.4.0 |
| Published | 2021-06-02 |
| First published | 2015-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 63.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Malte Legenhausen |
| Maintainers | mlegenhausen |
| Keywords | fetch, request, intercept, interceptor, hooks |

## Links

- npm: https://www.npmjs.com/package/fetch-intercept
- Repository: https://github.com/werk85/fetch-intercept
- Issues: https://github.com/werk85/fetch-intercept/issues
- npm.io page: https://npm.io/package/fetch-intercept

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 2.4.0 (latest) — 2021-06-02
- 2.3.1 — 2018-10-08
- 2.3.0 — 2018-09-13
- 2.2.3 — 2017-02-23
- 2.2.2 — 2017-02-22
- 2.2.1 — 2016-08-08
- 2.2.0 — 2016-03-29
- 2.1.0 — 2015-12-23
- 2.0.1 — 2015-11-05
- 2.0.0 — 2015-11-05
- 1.0.0 — 2015-10-20

## README

# fetch-intercept

[![Build Status](https://travis-ci.org/werk85/fetch-intercept.svg?branch=master)](https://travis-ci.org/werk85/fetch-intercept)

Interceptor library for the native fetch command inspired by [angular http interceptors](https://docs.angularjs.org/api/ng/service/$http).

`fetch-intercept` monkey patches the global `fetch` method and allows you the usage in Browser, Node and Webworker environments.

## Installation

```
npm install fetch-intercept --save
```

## Usage

_Note_: You need to require `fetch-intercept` before you use `fetch` the first time.

Make sure you have a `fetch` [compatible environment](http://caniuse.com/#search=fetch) or added a [appropriate polyfill](https://github.com/github/fetch).

```js
import fetchIntercept from 'fetch-intercept';

const unregister = fetchIntercept.register({
    request: function (url, config) {
        // Modify the url or config here
        return [url, config];
    },

    requestError: function (error) {
        // Called when an error occured during another 'request' interceptor call
        return Promise.reject(error);
    },

    response: function (response) {
        // Modify the reponse object
        return response;
    },

    responseError: function (error) {
        // Handle an fetch error
        return Promise.reject(error);
    }
});

// Call fetch to see your interceptors in action.
fetch('http://google.com');

// Unregister your interceptor
unregister();
```

## React-Native Compatibility
Support react-native `0.17` or higher versions.

## License
MIT

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