node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »

minimal-request

minimal-request Build Status

NPM

A minimal opinionated dependency-free request client for node.js.

  • It supports just GET and POST
  • It asks for gzip by default
  • When response status is not 200, it returns an error with the status code + the response.
  • Default timeout is 5 seconds. When request timesout, error is 'timeout'
var request = require('minimal-request');
 
request({
  url: 'https://hello.com/blabla',
  method: 'post',
  body: { hi: 'hello' },
  json: true,
  headers: { 'accept-language': 'en-GB' },
  timeout: 5 // seconds 
}, function(err, res, details){
  console.log(err);
  // -> something like 404 or null 
 
  console.log(res);
  // -> Something like {hi: 1234} 
 
  console.log(details);
  // -> Something like { statusCode: 200, headers: { ... }} 
});

License

MIT