1.0.2 • Published 4 years ago

@lawsoncheng/poke v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Poke

A lightweight and handy JS HTTP Client.

npm package

Dependency Status Known Vulnerabilities

Easy to use!

Poke is try to make http requests in the simplest way. See the following example:

const poke = require('@lawsoncheng/poke')

// Using promise
poke(
    // host url, starts with http or https
    'https://carlig.com', 
    // options
    {
        path : "/api/articles",
        method : "get"
    }
)
.then(result => {
    // result in plain text form
    console.log('> status code: ', result.statusCode)
    console.log('> body: ', result.body)
    // call json
    return result.json()
})
.then(json => {
    // here is the json object
    console.log('> json: ', json)
})
.catch(err => {
    console.log('> Error: ', err)
})

// using callback
poke(
    'https://carlig.com', 
    {
        path : "/api/articles",
        method : "get"
    },
    // callback
    (error, result) => {
        // Error object
        console.log('> error: ', error)
        // result object
        console.log('> status code: ', result.statusCode)
        console.log('> body: ', result.body)
        // to json
        result.json((json_error, json_result) => {
            // error on parsing?
            console.log('> parse json error:', json_error)
            // here is the json object
            console.log('> json: ', json)
        })
    }
)

Become a contirbutor!

Please see CONTRIBUTING.md

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago