New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@waldojeffers/rx-request

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@waldojeffers/rx-request

request + RxJs + JSONStream

latest
Source
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

rx-request

Dependency Status

request + RxJS + JSONStream

Description

A small node.js module that allows you to manipulate the result of an HTTP request as an observable sequence.

Installation

With npm :

npm install @waldojeffers/rx-request

Then, in a node.js file :

const RxRequest = require('@waldojeffers/rx-request');

Usage

RxRequest(url | options, [path = null])

where :

  • url | options (String | Object) : string URL, or an options object to pass to request
  • path (String) : a JSON path that will be passed to JSONStream.parse. Each element matched by this path will be emitted as a single element in the resulting observable sequence.

HTTP error handling : By default, if a request returns a statusCode which is not in the 2xx Success range (ie [200, 299]), the observable sequence will emit an error. Thus, you can make sure every request in your observable sequence has succeeded. Caution : if a single request fails, the entire observable sequence might fail as well if you use RxJs operators which do not handle errors (eg concatMap, flatMap).

RxRequest.HTTP_METHOD(url | options, [path = null])

where :

  • HTTP_METHOD : any HTTP method supported by request.

This is just a shorthand method (provided by request). All parameters are the same as above.

Examples

Without JSON path

The following request :

RxRequest.get('https://swapi.co/api/starships/').subscribe(...)

will give you the entire JSON response as one element in the observable sequence :

{
  "count": 37,
  "next": "http://swapi.co/api/starships/?page=2",
  "previous": null,
  "results": [
    {
      "name": "Death Star"
    },
    {
      "name": "Millennium Falcon"
    }
  ]
}

If you want to perform modifications on each starship in your observable sequence, you will need to use RxJs's flatMap or concatMap operator as follows :

RxRequest.get('https://swapi.co/api/starships/').flatMap(data => data.results).subscribe(...)

With a JSON path

The following request :

RxRequest.get('https://swapi.co/api/starships/', 'results.*').subscribe(...)

will emit each starship as an element of the observable sequence, avoiding you the extra flattening operation :

{
  "name": "Death Star"
}
{
  "name": "Millennium Falcon"
}

Keywords

rx

FAQs

Package last updated on 12 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts