1.0.2 • Published 2 years ago

@rxjsx/request v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

RxJSx Request

Tests Coverage Status NPM Version NPM Bundle Size

A simple RxJS-based HTTP client

Install

npm install --save @rxjsx/request rxjs

The library RxJS is a peer dependency. The library is tested with RxJS v6 and v7.

Usage

TypeScript + RxJS

import { request } from '@rxjsx/request';

interface GitHubAPIList {
  current_user_url: string;
}

request.get<GitHubAPIList>('https://api.github.com/')
  .subscribe(response => {
    const list: GitHubAPIList = response.json();
    console.log(list.current_user_url);
  });

JavaScript + Await

const { request } = require("@rxjsx/request");

const response = await request
  .get('https://httpbin.org/get')
  .toPromise();
console.log(response.json());

Try it here: https://runkit.com/aerabi/rxjsx-request-await

API

A name request is exported which is both a function and a namespace. One can call it directly by passing an object of type RequestOptions:

const { request } = require("@rxjsx/request");

request({ method: 'GET', path: 'https://httpbin.org/get' })
  .subscribe(console.log);

Or one can use the member functions:

const { request } = require("@rxjsx/request");

request.get('https://httpbin.org/get')
  .subscribe(console.log);

The full API is as follows:

export declare function request<T, R>(options: RequestOptions<T>): Observable<Response<R>>;
export declare namespace request {
  function get<R>(url: string, headers?: Record<string, string>): Observable<Response<R>>;
  function post<T, R>(url: string, body?: T, headers?: Record<string, string>): Observable<Response<R>>;
  function put<T, R>(url: string, body?: T, headers?: Record<string, string>): Observable<Response<R>>;
  function patch<T, R>(url: string, body?: T, headers?: Record<string, string>): Observable<Response<R>>;
  function del<R>(url: string, headers?: Record<string, string>): Observable<Response<R>>;
}

Notes

  • The functions return a singleton observable, meaning that the observable will contain one element (otherwise would error out).
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0-docs

3 years ago

1.0.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago