Pre configured fetch object ready to interact with Rest API. Receives @URL, @METHOD and @PAYLOAD.
npm install smallfetch_Smallfetch_ is a pre configured fetch object ready to interact with a Rest API
> Tiny implementation of 200B with no dependencies.
* It sets headers by default to 'application/json'.
* It _stringify_ object payload and pass it as body content for PUT/POST/PATCH.
* It parses server response to JSON.
* It throws a cachable error when the response is not in the range 200-299.
----------
bash
npm install smallfetch
`
`js
import sf from 'smallfetch';
`$3
#### Get - Search
`js
let books = await sf('https://example.com/books');
console.log(books);
`
#### Post - Create
`js
sf('https://example.com/books','POST',{name:'Book Name',desc:'Description'})
.then(response=>console.log(response))
.catch(error=>console.log('something is wrong',error));
`
#### Put - Update
`js
sf('https://example.com/books/1','PUT',{name:'Book Name',desc:'Description'})
.then(response=>console.log(response))
.catch(error=>console.log('something went wrong',error));
`To avoid throwing errors (for parallel request) pass false at the end of the request.
`js
Promise.all([
sf('https://example.com/books/1','POST',false),
sf('https://example.com/books/2','POST',false),
sf('https://example.com/books/3','POST',false)
]).then(results=>{
results.forEach(result=>console.log(result))
});
``