@ambassify/fetch-api

Small class to create easy to use API clients with fetch

Usage no npm install needed!

<script type="module">
  import ambassifyFetchApi from 'https://cdn.skypack.dev/@ambassify/fetch-api';
</script>

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');