All Projects → davguij → Rxios

davguij / Rxios

Licence: mit
A RxJS wrapper for axios

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Rxios

axios-for-observable
A RxJS wrapper for axios, same api as axios absolutely
Stars: ✭ 13 (-89.08%)
Mutual labels:  rxjs, observable, http-client, requests, axios, request, rx, observables
Redux Requests
Declarative AJAX requests and automatic network state management for single-page applications
Stars: ✭ 330 (+177.31%)
Mutual labels:  axios, http-client, frontend, front-end
rxrest
Reactive rest library
Stars: ✭ 33 (-72.27%)
Mutual labels:  rxjs, observable, request
observable-profiler
Tracks new & disposed Observable subscriptions
Stars: ✭ 41 (-65.55%)
Mutual labels:  rxjs, observable, observables
go-axios
HTTP Request package for golang.
Stars: ✭ 29 (-75.63%)
Mutual labels:  http-client, axios, request
Rxviz
Rx Visualizer - Animated playground for Rx Observables
Stars: ✭ 1,471 (+1136.13%)
Mutual labels:  rxjs, observable, rx
gists
Methods for working with the GitHub Gist API. Node.js/JavaScript
Stars: ✭ 96 (-19.33%)
Mutual labels:  requests, axios, request
Toy Rx
A tiny implementation of RxJS that actually works, for learning
Stars: ✭ 290 (+143.7%)
Mutual labels:  rxjs, rx, observables
Rx React Container
Use RxJS in React components, via HOC or Hook
Stars: ✭ 105 (-11.76%)
Mutual labels:  rxjs, observable, rx
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+561.34%)
Mutual labels:  rxjs, observable, request
Saber
⚔️ Saber, PHP异步协程HTTP客户端 | PHP Coroutine HTTP client - Swoole Humanization Library
Stars: ✭ 866 (+627.73%)
Mutual labels:  axios, http-client, requests
Dev Practice
Practice your skills with these ideas.
Stars: ✭ 1,127 (+847.06%)
Mutual labels:  frontend, front-end
Game Music Player
All your music are belong to us
Stars: ✭ 76 (-36.13%)
Mutual labels:  rxjs, observables
Rx Http Request
The world-famous HTTP client Request now RxJS compliant, wrote in full Typescript | ES6 for client and server side.
Stars: ✭ 117 (-1.68%)
Mutual labels:  observable, request
Graphql Rxjs
fork of Graphql which adds Observable support
Stars: ✭ 78 (-34.45%)
Mutual labels:  rxjs, observables
Angular1 Async Filter
Angular2 async pipe implemented as Angular 1 filter to handle promises & RxJS observables
Stars: ✭ 59 (-50.42%)
Mutual labels:  rxjs, observable
Ease
It's magic.
Stars: ✭ 1,213 (+919.33%)
Mutual labels:  observable, observables
Web Interview
我是「齐丶先丶森」,公众号「前端面试秘籍」作者,收集整理全网面试题及面试技巧,旨在帮助前端工程师们找到一份好工作!
Stars: ✭ 1,230 (+933.61%)
Mutual labels:  frontend, front-end
Http Client
A high-performance, high-stability, cross-platform HTTP client.
Stars: ✭ 86 (-27.73%)
Mutual labels:  http-client, request
Rx Connect
Glue your state and pure React components with RxJS
Stars: ✭ 86 (-27.73%)
Mutual labels:  rxjs, rx

Rxios

A RxJS wrapper for axios

npm CI bundlephobia

Rxios makes the awesome axios library reactive, so that it's responses are returned as RxJS observables.

Observables? Why?

Regular promises are cool, especially for HTTP requests in async/await functions.

However, Observables provide operators like map, forEach, reduce... There are also powerful operators like retry() or replay(), that are often quite handy.

Observables also excel when we need to perform some kind of manipulation on the received data, or when we need to chain several requests.

Lastly, Reactive stuff is what all the cool kids are doing.

Installation

npm install axios rxjs rxios

Usage

You can use Rxios by either

instantiating the class yourself

import { Rxios } from 'rxios';
const rxios = new Rxios({ /* options here */ })
const request = rxios.get(url)...

importing a "ready-to-use" generic instance

import { rxios } from 'rxios';
const request = rxios.get(url)...

In any case, please keep in mind that, when importing, Rxios refers to the class and rxios to the instance.

Syntax details

const { Rxios } = require('rxios');
// or import { Rxios } from 'rxios';

const http = new Rxios({
  // all regular axios request configuration options are valid here
  // check https://github.com/axios/axios#request-config
  baseURL: 'https://jsonplaceholder.typicode.com',
});

// plain GET request
http.get('/posts').subscribe(
  response => {
    console.log(response); // no need to 'response.data'
  },
  err => {
    console.error(err);
  }
);

// GET request with query params
http
  .get('/posts', { userId: 1 }) // you can pass an object as second param to the get() method
  .subscribe(
    response => {
      console.log(response); // no need to 'response.data'
    },
    err => {
      console.error(err);
    }
  );

// POST request
http
  .post('/posts', {
    // this object will be the payload of the request
    userId: 1,
    id: 1,
    title:
      'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
  })
  .subscribe(
    response => {
      console.log(response); // again, no need to 'response.data'
    },
    err => {
      console.error(err);
    }
  );

TypeScript usage

Rxios is written in TypeScript, and its typings are provided in this same package.

Also, just like with axios or with Angular's Http module, response types are accepted by the method, like:

import { Rxios } from 'rxios';
const http = new Rxios();
interface MyResponse = {userId: number; id: number; title: string};
http.get<MyResponse[]>('/posts/1')
  .subscribe(resp: MyResponse[] => {...});

Advanced usage

All Rxios methods always return an Observable, to which we can apply advanced RxJS operations.

For example, we could make two simultaneous requests and merge their responses as they come, without needing to wait for both to be completed.

import { Observable } from 'rxjs/Rx';
import { Rxios } from 'rxios';
const http = new Rxios();

const firstReq = http.get('/posts/1');
const secondReq = http.get('/posts/2');
firstReq.merge(secondReq).subscribe(...);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].