@ambassify/fetch-api

Small class to create easy to use API clients with fetch

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@ambassify/fetch-api
004.0.12 months ago6 years agoMinified + 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');