to-api
v0.3.10
Published
Library `to-api` generates REST API client with [`fetch`](https://fetch.spec.whatwg.org) under the hood.
Downloads
171
Maintainers
Readme
to-api
Library to-api
generates REST API client with fetch
under the hood.
Usage
import create from 'to-api';
const clientApi = create({ baseUrl: 'http://api/users' });
clientApi
.addHeader('Authorization', 'bearer ...')
.processResponse(({ data }) => data);
const usersClient = clientApi({
create: 'POST /',
updateById: 'PUT /:id',
deleteById: 'DELETE /:id',
find: '/',
findById: 'GET /:id'
});
(async () => {
const newUser = await usersClient.create({ email: '[email protected]' });
const user = await usersClient.findById({ id: 'user-id' });
})();
More examples you can find in tests.