Generate requests without need writing full request every time
npm i @bsaqqa/requestsgenerator
or
yarn add @bsaqqa/requestsgenerator
import API from '@bsaqqa/requestsgenerator';
API.setUrl('http://example.com/api/');
API.http.getProjects({page:1})
.then(response=>response.json())
.then(resp=>{
console.log(resp);
}).catch(err=>{
throw new Error('Response is inncorrect.');
});
more options
// GET /
API.http.get()
// GET /users
API.http.getUsers()
// GET /users/1234/likes
API.http.getUsers$Likes('1234')
// GET /users/1234/likes?page=2
API.http.getUsers$Likes('1234', { page: 2 })
// POST /items with body
API.http.postItems({ name: 'Item name' })
// other usage
API.setUrl('http://example.com/api/', '?attr=abc' )
// GET http://example.com/api/posts/123?attr=abc
API.http.getPosts$('1234')
// POST http://example.com/api/posts/123?attr=abc
API.http.postPosts$('1234', {name: 'user name'})