1.0.1 • Published 6 years ago

min-req-promise v1.0.1

Weekly downloads
4,037
License
Apache-2.0
Repository
github
Last release
6 years ago

Build Status codecov

Minimal Request Promise

request and request-promise are great, but I was looking for an some extra-light implementation.

Usage

client.<get|post|put|delete|head>(url, options)

  • url The full url to request
  • options an http.request options object. Can be extended with a body attribute.

response: An http.IncomingMessage object, complemented with a body attribute containing the response body data;

const client = require('min-req-promise');

return client.get('https://some/url')
  .then(response => {
    // response is an http.IncomingMessage
    // with an extra `body` member
    
    console.log(response.headers);
    console.log(response.body);
  });

Posting data

POST|PUT,.. body can be injected in options.body:

const client = require('min-req-promise');

return client.post('http://some/url', {
  headers: {
    'Content-type': 'application/x-www-form-urlencoded'
  },
  body: 'foo=bar'
})
  .then(response => {
    console.log(response);
  });