bsaqqa / requestsgenerator

Node library for generate requests without need writing full request every time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@bsaqqa/requestsgenerator

GitHub license npm (scoped)

Generate requests without need writing full request every time

Install

npm i @bsaqqa/requestsgenerator

or

yarn add @bsaqqa/requestsgenerator

Usage

    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'})

About

Node library for generate requests without need writing full request every time

License:MIT License


Languages

Language:JavaScript 100.0%