@poyoman/auto-fetch
v0.0.3
Published
Auto API based on fetch and JS Proxys
Downloads
3
Readme
auto-fetch
auto-fetch provides a Proxy generating fetch requests based on method names.
Quick start
npm i @poyoman/auto-fetch
const createAutoFetch = require('@poyoman/auto-fetch');
// ...
const api = createAutoFetch({
baseUrl: 'https://example.org',
headers: { /* some default headers */ },
});
api.users.get(); // GET https://example.org/users
api.user.jamy.setPreferences.post(); // POST https://example.org/user/jamy/setPreferences
api.user.jamy.setPreferences(); // POST is default request method => POST https://example.org/user/jamy/setPreferences
Doc
createAutoFetch(options)
Create a new api
- options.baseUrl (required) string: Base url of future requests
- options.headers (default: null) object: default headers of future requests
api.some.path.method()
You can put as much url segments before calling the function.
method can be any REST method (get, post, put, patch, delete)