fuzzy-requests v1.0.2
FuzzyRequests
FuzzyRequests is a simple fetch wrapper meant to provide some simple boilerplate, and mapping operations.
Usage:
const FR = require("fuzzy-requests")
//provide your base url within the constructor
const req = new FR({base:"https://jsonplaceholder.typicode.com"})
//perform a single get request
req.get({endpoint:"/posts/1"}).then(done => console.log(done)}).catch(err => console.log(err))
//perform multiple get requests
req.getMap([
{endpoint:"/posts/1"},
{endpoint:"/posts/2"},
{endpoint:"/posts/10"}
]).then(done => {
//array of map results
}).catch(err => console.log(err))
All request types will always return a Promise.
Each request type accepts a single object argument with the following properties:
endpoint : "/your-api-end-point?queryParam=123" token: "your-unique-token-string" body: {Hello:"World"}
For instance, if your endpoint requires a token and a "user object", to post to "/users" you would make the following request
req.post({endpoint:"/users", token:"sdsfR$drsdgdst%tDfdsfsdgh@@WQD%...", body:{firstName:"Fuzzy", lastName:"Requests"})
The endpoint will be appended to your base url, the token will be appended to "Authorization: Bearer" within the Headers object, and the body will be JSON.stringified.
The following requests/operations are available:
get / getMap post / postMap delete / deleteMap update / updateMap patch / patchMap