nodeh

1.0.1 • Public • Published

Nodeh

Nodeh (pronounced node-h) is a simple utility class that wraps Axios' HTTP request module to simplify the usage by chaining methods which at then end, the code is readable and easy to understand.

Installation

npm i nodeh

Usage

Nodeh is a class so you need to import and then instantiate it. Then the methods can be chained together to complete an HTTP request.

const nodeh = require('nodeh');
 
 
// example 1: GET request
let get_request = new nodeh();
get_request
    .addUrl('http://bing.com')                           //add the url of the request
    .send()                                              //send the request
    .then( (result) => { console.log(result.data) } )    //what happens on success
    .catch( (error) => { console.log(error) } )          //what happens on error
 
// example 2: POST request
let post_request = new nodeh();
request
    .addUrl('https://reqres.in')                         //can also use addUrl('https://reqres.in/api/user')
    .addPath('/api/users')                               //and don't call addPath('/api/users')
    .addMethod('POST')
    .addHeaders({"Accept": "application/json"})
    .addData({
        name: "Channing Tatum",
        quote: "My name is Jeff"
    })
    .send()
    .then( result => { console.log(result.data) } )
    .catch( error => { console.log(error) } )

Go ahead and give it a try :)

Please let me know of any feedback at @mohsenari on Twitter or @mohsenari on Github.

Package Sidebar

Install

npm i nodeh

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

3.73 kB

Total Files

4

Last publish

Collaborators

  • mohsenari