Socket
Book a DemoInstallSign in
Socket

yarp

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yarp

Yet Another Request-Promise - Overly-simple promise wrapper around the amazing request module

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
7
133.33%
Maintainers
1
Weekly downloads
 
Created
Source

YARP (Yet Another Request-Promise)

npm version Build Status

There is a glut of promise-based wrappers around the awesome request module (https://github.com/request/request).

This is yet another one.

Overly Simple:

var yarp = require('yarp');

yarp({
  method: 'GET',
  url: 'http://jsonplaceholder.typicode.com/users',
}).then(function(resp){           // resolves if statusCode < 400
  console.log(resp);
}).catch(function(err){           // rejects with object otherwise
  if(err.statusCode) {            // server responded with statusCode >= 400
    console.log(err.statusCode);
    console.log(err.message);     // if the server gave a message as part of its response
    console.log(err.data);        // the data received from the server (if present)
    console.log(err.request);     // the original request options
  } else {
    console.log(err)              // internal client error
  }
}).done();

As of 0.4.0, you can now pass true as a second parameter to have all responses treated as resolution:

var yarp = require('yarp');

yarp({
  method: 'GET',
  url: 'http://jsonplaceholder.typicode.com/users',
}, true).then(function(resp){     // resolves for any status code
  console.log(resp.statusCode);   // status code from the response
  console.log(resp.data)          // response from the servdr, parsed if valid JSON
  console.log(resp.body)          // raw response
}).catch(function(err){
  console.log(err)                // rejects with internal client error
}).done();

Keywords

request

FAQs

Package last updated on 19 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.