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

request-resource

v1.0.0

Published

๐Ÿš€ ๐Ÿ”ฅ Promise based HTTP client for the browser and node.js

Downloads

1

Readme

Request Resource

๐Ÿš€ ๐Ÿ”ฅ Promise based HTTP client for the browser and node.js

Installation

Using npm:

npm install request-resource

Using yarn:

yarn add request-resource

Example

Get resource from an endpoint

import resource from 'request-resource'

resource
    .get('https://jsonplaceholder.typicode.com/posts/1')
    .then(d => console.log(d))
    .catch(e => console.error(e))

// Response ->
/*
    {
        data: {
            body: "quia et suscipit....."
            id: 1
            title: "sunt aut facere....."
            userId: 1
        }, 
        headers: {
            cache-control: "public, max-age=14400"
            content-type: "application/json; charset=utf-8"
            expires: "Mon, 12 Nov 2018 20:40:35 GMT"
            pragma: "no-cache"
        }, 
        statusCode: 200
    }
*/

NOTE: async/await is part of ECMAScript 2017 and is not supported in Internet Explorer and older browsers, so use with caution.

Performing a POST request

import resource from 'request-resource'

resource
    .post('https://jsonplaceholder.typicode.com/posts', {
        title: 'new Post',
        body: 'new post body',
    })
    .then(d => console.log(d))
    .catch(e => console.error(e))

Available methods

  • resource.get(url, formData , [, config])
  • resource.post(url, formData , [, config])
  • resource.delete(url, formData , [, config])
  • resource.put(url, formData , [, config])
  • resource.head(url, formData , [, config])
  • resource.option(url, formData , [, config])
  • resource.head(url, formData , [, config])

url: (String) Resouce endpoint url formData: (Object) data to be sent as the request body. Only applicable for request methods PUT, POST, and PATCH config: (Object) configaration object of request-resource library

config object schema

// todo: add moto config to config
{
    headers: {
    }
}

Response Schema

{
  // `data` is the response that was provided by the server
  data: {},

  // `status` is the HTTP status code from the server response
  statusCode: 200,

  // `headers` the headers that the server responded with
  // All header names are lower cased
  headers: {},
}