# redux-saga-requests-fetch

> Fetch API driver for Redux-Saga-Requests, Redux-Saga addon to simplify AJAX requests

Latest version **0.10.0** (published 2020-03-22) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install redux-saga-requests-fetch
pnpm add redux-saga-requests-fetch
yarn add redux-saga-requests-fetch
bun add redux-saga-requests-fetch
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.10.0 |
| Published | 2020-03-22 |
| First published | 2017-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 46.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 366 |
| Author | Konrad Lisiczynski |
| Maintainers | klis87 |
| Keywords | redux, redux-saga, axios, fetch, ajax |

## Links

- npm: https://www.npmjs.com/package/redux-saga-requests-fetch
- Repository: https://github.com/klis87/redux-saga-requests
- Issues: https://github.com/klis87/redux-saga-requests/issues
- npm.io page: https://npm.io/package/redux-saga-requests-fetch

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) >=0.16.0
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.2.0

## 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

- 0.10.0 (latest) — 2020-03-22
- 0.9.7 — 2019-09-01
- 0.9.6 — 2019-01-05
- 0.9.5 — 2018-12-29
- 0.9.4 — 2018-11-17
- 0.9.3 — 2018-11-05
- 0.9.2 — 2018-09-15
- 0.9.1 — 2018-08-19
- 0.9.0 — 2018-08-15
- 0.8.0 — 2018-07-22
- 0.7.0 — 2018-07-15
- 0.6.1 — 2018-05-27
- 0.6.0 — 2018-01-28
- 0.5.0 — 2017-12-06
- 0.4.1 — 2017-12-03
- … 1 more at https://npm.io/package/redux-saga-requests-fetch/versions

## README

# redux-saga-requests-fetch

[![npm version](https://badge.fury.io/js/redux-saga-requests-fetch.svg)](https://badge.fury.io/js/redux-saga-requests-fetch)
[![Build Status](https://travis-ci.org/klis87/redux-saga-requests.svg?branch=master)](https://travis-ci.org/klis87/redux-saga-requests)
[![Coverage Status](https://coveralls.io/repos/github/klis87/redux-saga-requests/badge.svg?branch=master)](https://coveralls.io/github/klis87/redux-saga-requests?branch=master)
[![Known Vulnerabilities](https://snyk.io/test/github/klis87/redux-saga-requests/badge.svg)](https://snyk.io/test/github/klis87/redux-saga-requests)
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lernajs.io/)

Fetch API driver to Redux-Saga - addon to simplify handling of AJAX requests.

## Installation

To install the package, just run:
```
$ yarn add isomorphic-fetch redux-saga-requests-fetch
```
or...
```
$ npm install isomorphic-fetch redux-saga-requests-fetch
```
or you can just use CDN: `https://unpkg.com/redux-saga-requests-fetch`.

## Usage

For a general usage, see [redux-saga-requests docs](https://github.com/klis87/redux-saga-requests).

Regarding Fetch API related usage, here you can see a typical setup:
```js
import 'isomorphic-fetch'; // or a different fetch polyfill
import { handleRequests } from 'redux-saga-requests';
import { createDriver } from 'redux-saga-requests-fetch';

handleRequests({
  driver: createDriver(
    window.fetch,
    {
      baseURL: 'https://my-domain.com' // optional - it works like axios baseURL, prepending all relative urls
      AbortController: window.AbortController, // optional, if your browser supports AbortController or you use a polyfill like https://github.com/mo/abortcontroller-polyfill
    }
  ),
});
```
And in order to create Fetch API requests, below:
```js
fetch('/users', {
  method: 'POST',
  body: JSON.stringify(data),
  headers: {
    'Content-Type': 'application/json',
  },
});
```
should be translated to this:
```js
const fetchUsers = () => ({
  type: 'FETCH_USERS',
  request: {
    url: '/users/',
    method: 'POST',
    body: JSON.stringify(data),
    headers: {
      'Content-Type': 'application/json',
    },
  }
});
```
The point is, you can use the same request config like you do with pure Fetch API, but you need to pass `url` in the
config itself. Also, one additional parameter you could provide in the config is `responseType`, which is set as `json`
as the default. Available response types are: `'arraybuffer'`, `'blob'`, `'formData'`, `'json'`, `'text'`, or `null`
(if you don't want a response stream to be read for the given response).

Also, this driver reads response streams automatically for you (depending on `responseType` you choose)
and sets it as `response.data`, so instead of doing `response.json()`, just read `response.data`.

## Licence

MIT

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