# rest-fetcher

> REST API Fetcher module.

Latest version **1.0.18** (published 2019-03-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install rest-fetcher
pnpm add rest-fetcher
yarn add rest-fetcher
bun add rest-fetcher
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.18 |
| Published | 2019-03-24 |
| First published | 2018-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Izik Orgad |
| Maintainers | iziko |
| Keywords | REST, API, fetch, request, fetcher |

## Links

- npm: https://www.npmjs.com/package/rest-fetcher
- Repository: https://github.com/izikorgad/fetcher
- Homepage: https://github.com/izikorgad/fetcher#readme
- Issues: https://github.com/izikorgad/fetcher/issues
- npm.io page: https://npm.io/package/rest-fetcher

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) ^2.2.1

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

- 1.0.18 (latest) — 2019-03-24
- 1.0.17 — 2019-03-19
- 1.0.15 — 2019-03-19
- 1.0.14 — 2019-03-19
- 1.0.13 — 2018-11-22
- 1.0.12 — 2018-11-21
- 1.0.11 — 2018-07-25
- 1.0.10 — 2018-07-25
- 1.0.9 — 2018-07-04
- 1.0.7 — 2018-07-03
- 1.0.6 — 2018-07-03
- 1.0.5 — 2018-07-02
- 1.0.4 — 2018-02-01
- 1.0.2 — 2018-02-01
- 1.0.1 — 2018-02-01
- … 1 more at https://npm.io/package/rest-fetcher/versions

## README

rest-fetcher
============

[![npm version](https://img.shields.io/npm/v/rest-fetcher.svg?style=flat-square)](https://www.npmjs.com/package/rest-fetcher)
[![npm downloads](https://img.shields.io/npm/dm/rest-fetcher.svg?style=flat-square)](https://www.npmjs.com/package/rest-fetcher)

A simple REST API fetcher module.

## Install

```sh
$ npm install rest-fetcher --save
```

## Features

- Lightweight REST API module.
- Support both browser and node.js runtime environment (based on isomorphic-fetch).
- Built-in client-side timeout.
- Error handling.

## Usage
```javascript
import { Fetcher } from 'rest-fetcher';
const config = {baseUrl: 'http://<your_server_url>'};
const fetcher = new Fetcher(config);


// For GET requests
// args are optional key-value paris for query parameters.
const response = await fetcher.get('/some/api/path', [ { p1: 'k1' }, { p2: 'k2' } ]);

// For POST requests
 response = await fetcher.post('/some/api/path', body);

 // For PUT requests
 response = await fetcher.put('/some/api/path', body);

 // For PATCH requests
 response = await fetcher.patch('/some/api/path', body);

 // For DELETE requests
 response = await fetcher.delete('/some/api/path', body);


 // Fetcher module has a built-in client-side timeout (set to 1 minute by default)
 // You can set your own default by sending a second parameter to the constructor:
 const config = {baseUrl: 'http://<your_server_url>', defaultTimeout: 12000};
 const fetcher = new Fetcher(config);

 // Furthermore, you can overwrite the default timeout on a specific API call:
 response = await fetcher.post('/some/api/path', body, 300000);


```

## Headers Support
```javascript
import { Fetcher } from 'rest-fetcher';

// You can assign default headers (optional) that will be sent upon each request
const config = {
        baseUrl: 'http://<your_server_url>',
        defaultHeaders: { 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json' }
      };

const fetcher = new Fetcher(config);


// Or send headers for a specific request (in this case those headers will be added to the default).
const response = await fetcher.get('/some/api/path', body, headers);


```

## Credentials Mode Support
```javascript
import { Fetcher } from 'rest-fetcher';

// You can set credentials mode (optional) that will be sent upon each request
const config = {
        baseUrl: 'http://<your_server_url>',
        credentialsMode: "include" // | "same-origin" | "omit"
      };

const fetcher = new Fetcher(config);

```

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