📡 req
Tiny and lightweight promise based HTTP(S) request library (70 sloc)
Table of Contents
Table of Contents
Install
Usage
API
CLI
Contribute
License
Install
$ npm install --save puny-req
$ yarn add puny-req
Usage
const req = require('puny-req')
req('https://jsonplaceholder.typicode.com/posts/1').then((res) => {
console.log(res.headers, res.body)
}).catch(console.log)
req({
url: 'https://jsonplaceholder.typicode.com/posts',
json: {
title: 'Hi', body: 'Friend', userId: 1
}
}).then((res) => {
console.log(res.headers, res.body)
}).catch(console.log)
API
Module exports a single function that returns a promise. It accepts a url string as argument for simple GET requests or an object with the following options:
{
url: String,
port: Int,
headers :Object,
method: String,
auth: String,
encoding: String
form: Object || String,
json: Object
}
The promise resolves with the response object. The body is parsed to a object if possible.
CLI
The CLI is currently a work in progress.
Contribute
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
Note: If editing the README, please conform to the standard-readme specification.
License
Licensed under the MIT License.