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

rauricoste-request

v2.0.2

Published

a promise wrapper around http.request and https.request. Also provide a functionnal builder.

Downloads

36

Readme

Summary

rauricoste-request is a fluent api to send HTTP request using Promise as its core data object.

It is written using nodejs libraries. Then, it should be compiled with a tool like browserify

API

A HTTP call consists on some modifiers calls followed by a callers call. It will always return a Promise. If the HTTP code is >= 400, the promise response will contain an error with details.

Exemple :

new Request()
        .json()
        .withHeader("Authorization", "Bearer 12345")
        .withQueryParams({
            start_time: "2017-01-01",
            end_time: "2017-12-31"
        })
        .get("https://api.domain.com").then(response => {
            // extract the response body and status code
            const { body, statusCode } = response;
            // parse the body as a json object
            const json = JSON.parse(body);
        }).catch(err => {
            // extract the response and request
            const { request, res } = err;
            // extract the response status code and the response body
            const { statusCode, body } = res;
        })

callers

  • get(url) : launch the request with the method GET on the url url

  • post(url, body) : launch the request with the method POST on the url url with the body body.

body can be a string or an object (cf withBody method)

  • call(url) : launch the request with the current method provided by withMethod on the url url.

Default method is GET

modifiers

  • withBody(string or object) : add a body to the request. If the body is an object, it will convert it the same way it does for query parameters. If calling a POST, you shoud pass an object. If calling a JSON API, you should convert the object to JSON using JSON.stringify(object)

Exemple : withBody({start: 2017, end: 2018}) will convert to start=2017&end=2018.

  • withQueryParams(string or object) : adds query parameters on the url called. If this method is called several times, only last call is effective.

Exemple : withQueryParams({start: "a", end: "z"}) : will add start=a&end=z

  • withHeaders(object) adds a list of headers

Exemple : withHeaders({Authorization: "Bearer 12345"}) : adds the header Authorization: Bearer 12345

  • withHeader(key, value) adds a header

Exemple : withHeaders("Authorization", "Bearer 12345") : adds the header Authorization: Bearer 12345

  • withMethod(value) : will change the HTTP method. Methods can be GET, PUT, POST, DELETE, .... Defaults : GET

  • withUrl(url) : will change the base URL called. This method will not modify query parameters

  • withCredentials(boolean) : if set to true, credentials will be sent. It can be usefull when using CORS

content-types

  • talkType(type) : is a shortcut for .withHeaders({"Content-Type": type, "Accept": type})

  • json() : is a shortcut for .talkType("application/json")

  • xml() : is a shortcut for .talkType("application/xml")