Skip to content

A thin Promise wrapper around Node.js http/https request functions

License

Notifications You must be signed in to change notification settings

tonybadguy/small-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

A thin Promise wrapper around Node.js http/https request functions

Resources

License

Stars

Watchers

Forks

Packages

No packages published