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

bees-request

v1.1.6

Published

A promise based simple abortable http client for node, browsers and React Native.

Downloads

4

Readme

bees-request npm version

A promise based simple abortable http client for node and browsers. bees-request uses the http or https modules on node and the XMLHttpRequest on browsers and React Native.

Installation

NPM:

npm install bees-request

CDN:

<script src="https://unpkg.com/bees-request/umd/bees-request.min.js"></script>

Usage

beesRequest.fetch(url[, options][, callback])
beesRequest.fetch(options)

options object has the following proprties:

  • url: the url for the request. If the url is specified as a fetch argument it overwrites the value in the options object if present
  • method: the method for the request. Default: GET
  • data: optional data to be appended to the querystring (GET) or sent in the request body (POST)
  • headers: optional key/value to be added to the request HTTP headers
  • timeout: optional timeout for the request (in milliseconds)
  • callback: an optional function to be called when the request is sent. If the callback is specified as a fetch argument it overwrites the value in the options object

Basic GET request:


beesRequest.fetch('http://example.com/api')
  .then(function(response) {
    // response is an instance of beesResponse object
    // it has the following methods:
    // response.json() returns a json object 
    // response.text() returns the plain text object
    // response.toString() alias to .text()
    console.log(response.text())
  })
  .catch(function(error) {
    // error is an instance of beesError
    // it has the following properties:
    // error.message
    // error.code
    // error.isAborted - an error is raised when the request is aborted
    console.log(error.message);
  });

POST Request with data:

  
beesRequest.fetch({
  url: 'http://example.com/api',
  method: 'POST', 
  data: { 
    id: 1234
  }
})
  .then(function(response) {
    console.log(response.text())
  })
  .catch(function(error) {
    console.error(error.message)
  });

Abort example:

var request = null;

beesRequest.fetch({
  url: 'http://example.com/api',
  callback: function(req) {
    request = req
  }
})
  .then(function(response) {
      console.log(response.text())
  })
  .catch(function(error) {
    if(error.isAborted) {
      // the request has been aborted
    } else {
      console.error(error.message)
    }
  });

request.abort();

Aliases:

beesRequest.get(url[, options][, callback]) // equivalent to fetch(url, options, callback) with options.method = 'GET'
beesRequest.get(options) // equivalent to fetch(url, options, callback) with options.method = 'GET'

beesRequest.post(url[, options][, callback]) // equivalent to fetch(url, options, callback) with options.method = 'POST'
beesRequest.post(options) // equivalent to fetch(url, options, callback) with options.method = 'POST'