@ambassify/fetch-api

Small class to create easy to use API clients with fetch

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
00Apr 29, 2020Mar 16, 2017Minified + gzip package size for @ambassify/fetch-api in KB

Readme

fetch-api

CircleCI npm version npm downloads maintainer

Small class to create easy to use API clients with fetch. It uses @ambassify/fetch under the hood to provide a default fetch implementation for browser and node.

Usage

Install the package in your project:

npm install --save @ambassify/fetch-api

In your code:

const FetchApi = require('@ambassify/fetch-api');

const api = new FetchApi({
    baseUrl: 'https://your-api.test',
    contentType: 'FORM',
});

api.get('/foo', { offset: 1, limit: 1 })
    .then(res => console.log(res.body))
    .catch(err => console.log(err));

api.post('/foo', { foo: 'bar' });
api.put('/foo/1', { foo: 'bar' });
api.patch('/foo/1', { foo: 'bar' });
api.delete('/foo/1');

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.