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

rxjs-fetch

v2.1.6

Published

RxJS-flavored version of HTTP fetch API for node.js (for RxJS 5.0+)

Downloads

51

Readme

rxjs-fetch Build Status Coverage Status js-semistandard-style

RxJS-flavored version of HTTP fetch API for node.js.

IMPORTANT: This library only supports RxJS 5.x.

Looking for RxJS 4.x support? Try rx-fetch. (Same name but replace 'rxjs' with 'rx'.)

Built on top of isomorphic-fetch.

Warnings

  • This adds fetch as a global so that its API is consistent between client and server.
  • You must bring your own ES6 Promise compatible polyfill. I suggest es6-promise.

Installation

NPM

npm install --save rxjs-fetch

Usage

const rxFetch = require('rxjs-fetch');

rxFetch('http://tangledfruit.com/mumble.txt')
  .subscribe(
    response => {
      /*
        Occurs exactly once. "response" is an Object with the following properties:

          - status (Number): HTTP status code
          - ok (Boolean): true if status < 400
          - statusText (String): HTTP status string
          - headers (Object): Maps HTTP headers in the response to string values
          - url (String): URL that was requested.

        "response" has the following methods:

          - text: Returns another Observable which resolves with the response body
            as a String when available.

          - json: Returns another Observable which resolves with the response body
            parsed as JSON (i.e. an Object or Array) when available.

          It is an error to call more than one of these methods or to call any
          of these methods more than once.
      */
    },
    err => {
      console.log(err);
      // Should only happen if unable to reach server.
      // Server error responses (status code >= 400)
      // are not automatically mapped to errors.
    });

There are some shortcut methods available on the Observable object that is returned from rxFetch:

rxFetch('http://tangledfruit.com/mumble.txt').failOnHttpError()
  // -> This Observable will yield an error notification using the HttpError
  // object described below if the HTTP status code is >= 400.
rxFetch('http://tangledfruit.com/mumble.txt').failIfStatusNotIn([200, 404])
  // -> This Observable will yield an error notification using the HttpError
  // object described below if the HTTP status code is anything other than the
  // codes listed (in this case, 200 and 404).
rxFetch('http://tangledfruit.com/mumble.txt').text()
  // -> This Observable will yield a next notification containing only the
  // body text of the HTTP response. The HTTP headers and status are discarded.
  // This call implies .failOnHttpError().
rxFetch('http://tangledfruit.com/mumble.txt').json()
  // -> This Observable will yield a next notification containing only the
  // body of the HTTP response parsed as JSON. The HTTP headers and status are
  // discarded. This call implies .failOnHttpError().
const recording = new Rx.ReplaySubject(); // can be any Subject
rxFetch('http://tangledfruit.com/mumble.txt').recordTo(recording).json()
  // -> Same as above, but it will capture the request and response and
  // send it to the Subject in a syntax that can then be used to write unit
  // tests using Nock. (See rxjs-fetch's own unit tests for an example.)
  // You can also invoke this by adding recordTo: subject in the options
  // object on the .get method.

HTTP Error object

The .failOnHttpError and .failIfStatusNotIn methods will send an error notification with an HttpError object. This is the standard Error Object, but it has an extra member response from which you can access other properties as described earlier.

The message for the error will be "HTTP Error (status code): (server message)". For example, "HTTP Error 404: Not Found".

License

MIT