npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

q-wrapped-request

v2.0.4

Published

A Q-promise request library wrapper

Downloads

14

Readme

QRequest

A Q-promise request node module wrapper. It will produce Q-promises for request methods:

  • del
  • get
  • head
  • patch
  • post
  • put

Build Status Coverage Status

Installation

npm install q-wrapped-request

Note: The module is using peerDependencies to require Q and request, so your project may have its own dependencies on both libraries installed.

Fulfillment

A fulfillment handler will receive an array of request callback params:

  • response
  • body

So the typical request chain may look like:

    (new Request).get("http://echo.jsontest.com/key/value/one/two")
        .spread(function(response, body){
            // Process your body here...
        });

Constructor

A QRequest constructor will accept an options param that will call defaults of request internally and use this request for further requests:

    it ("should use bound properties for further requests", function(){
        var r = new Request({url: "http://echo.jsontest.com/key/value/one/two"});
        return r.get(undefined)
            .spread(function(response, body){
                return JSON.parse(body);
            }).should.eventually.deep.equal({
                "one": "two",
                "key": "value"
            });
    });

raw

Both QRequest class and its instances will have a raw property for convenience.

  • QRequest raw is just a request itself.
  • Instance raw property is a request produced by calling defaults as a constructor.

Getting body

For more convenience QRequest expose two utility functions to get body:

bodyIfStatusOk

Returns body if response status is one of the allowed:

    it ("should fail on incorrect status using 'bodyIfStatusOk' shortcut", function(){
        return (new Request).get("http://echo.jsontest.com/key/value/one/two")
            .spread(Request.bodyIfStatusOk(500))
            .should.eventually.be.rejectedWith(RangeError);
    });

body

Returns body if response status is 200:

    it ("should get body if response status is 200 using a 'body' shortcut", function(){
        return (new Request).get("http://echo.jsontest.com/key/value/one/two")
            .spread(Request.body)
            .then(JSON.parse)
            .should.eventually.deep.equal({
                "one": "two",
                "key": "value"
            });
    });