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

kusarequest

v0.5.1

Published

Promisified simple request module. This module focuses on chainable request.

Downloads

3

Readme

kusarequest

Promisified simple request module. This module focuses on chainable request.
This module is wrapped to request and bluebird.

Installation

$ npm i kusarequest
var Kusarequest = require("kusarequest");

new Kusarequest.get(...)

Usage

Basic request

Kusarequest will use in the instance. And instance will request in the HTTP method.
Kusarequest support HTTP method => ["get", "head", "post", "put", "patch", "del"]

It return Promise. Promise's Argument is Kusarequest instance.

new Kusarequest().get("https://example.com").then(function(kusarequest) {
    assert.strictEqual(kusarequest.res.body, "get");
});

Request with option

Option is equivalent to the request module option.

For more information see here

new Kusarequest().get("https://example.com/option", {
  "qs": {
    "key": "get_value"
  }
})
.then(function(kusarequest) {
  assert.strictEqual(kusarequest.res.body, "get_value");
});

Request with callback

Promise to return from the callback is executed.
Callback of this it has been bound from the instance.

new Kusarequest().get("https://example.com", function(res) {
  // [this] is bound from the Kusarequest instance
  this.container = res.body + "container";
})
.then(function(kusarequest) {
  assert.strictEqual(kusarequest.container, "getcontainer");
});

Request with option and callback

Kusarequest().get("https://example.com/option", {
  "qs": {
    key: "get_value"
  }
}, function(res) {
  this.container = res.body + "container";
})
.then(function(kusarequest) {
  assert.strictEqual(kusarequest.container, "get_valuecontainer");
});

Feature

Chaninable

Kusarequest has a method chain concept.

Kusarequest().post("https://example.com/form", {
  "form": {
    "key": "post_value"
  }
})
.then(function(kusarequest) {
  assert.strictEqual(kusarequest.res.body, "post post_value");
});

path only ok

Uri of the instance is okay only path.

Kusarequest().get("https://example.com/")
.then(function(kusarequest) {
  // this is request to https://example.com/some/path
  return kusarequest.get("/some/path");
})
.then(function(kusarequest) {
  assert.strictEqual(kusarequest.res.body, "path");
});

Continuation of cookie

Kusarequest instance will take over the cookie of the each request.
This is useful, for example, when you are scraping after login.

kusarequest.post("https://example.com/login", {
  "form": {
    "id": "id",
    "password": "password"
  }
})
.then(function (kusareq) {
  // kusareq keep logged in (cookie)
  kusareq.get(...)
})

You can also set the cookie-jar when you make the instance.

var jar;

new Kusarequest().post("https://example.com/login")
.then(function(kusarequest) {
  jar = kusarequest.jar(); // get logged in jar
})

// set logged in jar
new Kusarequest(jar).get("/after/login/pass");
  .then(function(kusarequest) {
    assert.strictEqual(kusarequest.res.body, "success");
});

Follow all redirect

Redirection of GET and non-GET HTTP method is automatically follow.

// exsample) /redirect-from -- redirect --> /redirect-to
kusarequest.get("/redirect-from")
.then(function (kusareq) {
  console.log(kusareq.url) // /redirect-to
});

// nod-GET redirects support by default.
kusarequest.post("/redirect-from")
.then(function (kusareq) {
  console.log(kusareq.url) // /redirect-to
});

Response history

Kusarequest instance has a history of each response to r_histories property.

Kusarequest().get(BASE_URL)
.then(function(kusareqest) {
  return kusareqest.get("/path");
})
.then(function(kusareqest) {
  return kusareqest.get("/option", {"qs": {"key": "option"}});
})
.then(function(kusareqest) {
  var bodys = kusareqest.r_histories.map(function(res) {
    return res.body;
  });
  assert.strictEqual(bodys.join(" "), "option path get");
});

Instance property and method

instance propaty is this.

property

  • res - request's response.toJSON()
  • raw_res - original request response
  • r_history - res history
  • container - Use this when you want to exceed the each [then]

method

  • jar - get cookie-jar