small-request

2.1.0 • Public • Published

small-request

npm version Build Status codecov

This Node.js module is a thin wrapper around the Node.js http/https request functions that provides:

  • A Promise interface
  • Handling of response chunking
  • Auto-selection of the http/https request function

The promise is resolved when:

  • A response is received from the server regardless of status code

The promise is rejected when:

  • Any other exception is encountered

Example usage:

const request = require('small-request');

request.send({
  url: 'https://httpbin.org/get'
}).then(response => {
  console.log(response.body);
});

RequestModel

The request.send(requestModel) function takes in a requestModel object. This object is an extended version of the Node.js http.request options object. Its extended fields are:

  • url (string)
  • body (string)
  • socketTimeout (number in milliseconds)

If the original http.request option field values conflict with the extended field values, then the original field values take precedence.

ResponseModel

The promise returned by request.send() resolves to an object with the following fields:

  • body (string)
  • headers (object)
  • statusCode (number)

Package Sidebar

Install

npm i small-request

Weekly Downloads

991

Version

2.1.0

License

MIT

Unpacked Size

14.5 kB

Total Files

13

Last publish

Collaborators

  • tonybadguy