Giter VIP home page Giter VIP logo

request's Introduction

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).

request's People

Contributors

aerabi avatar

Forkers

aerabi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.