Skip to content

alicoding/fetch-restful-json

Repository files navigation

fetch-restful-json

Simple RESTful APIs for fetch clients.

Usage

Installation

yarn add --dev fetch-restful-json

Example

Define a resource object:

import fetchRestfulJson from 'fetch-restful-json';

const restfulFetch = fetchRestfulJson({
  base: '/api/v1'
});

const cakes = restfulFetch.service('cakes'); // Define resource '/api/v1/cakes'

Use it to make requests. Every method returns a promise that resolves to the JSON object returned in the body of the response.

await cake = cakes.create({ name: 'Chocolate' }); // POST request

await cake = cakes.update(cake.id, cake); // PUT request
await cake = cakes.patch(cake.id, cake); // PATCH request

await result = cakes.remove(cake.id); // DELETE request

await cakes = cakes.find(); // GET request

About

Yet another simple RESTful APIs for fetch clients.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •