@poyoman/auto-fetch

0.0.3 • Public • Published

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)

Package Sidebar

Install

npm i @poyoman/auto-fetch

Weekly Downloads

0

Version

0.0.3

License

LGPL 2.1

Unpacked Size

30.8 kB

Total Files

7

Last publish

Collaborators

  • poyoman