0.9.0 • Published 7 years ago

ts-rx-rest v0.9.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

ts-rx-rest

RxJs Http client for Typescript.

npm version

Provides convenient typed wrappers for http verbs:

  • doGet
  • doPost
  • doPut
  • doDelete

Install

$ npm install --save ts-rx-rest

Since rx 4.* doesn't have @types, you have to manually install rx and define correct typings as follows:

$ npm install --save rx

Create file index.d.ts along with package.json with the following content:

/// <reference path="node_modules/rx/ts/rx.all.d.ts" />

Usage

import Rest, {errorInterceptor, jsonInterceptor, withCredentialsInterceptors} from 'ts-rx-rest';

const rest = new Rest()
    .wrapRequest(withCredentialsInterceptors) // or .withCredentials()
    .wrap(errorInterceptor) // forwards an XMLHttpRequest object to an error branch of the observable
    .wrap(jsonInterceptor); // converts text representation of the response to json

rest.doGet<Array<User>>('/users').subscribe(users => console.log(users));

Custom interceptors

Request interceptors

const withCredentialsInterceptors = (r: XMLHttpRequest) => {
    r.withCredentials = true;
    return r;
};

Response interceptors

const accessDenied = (observable: Observable<any>) =>
    observable.doOnError(err => {
        if (err.response.status === 403 || err.response.status === 401) {
            // Do some stuff
        }
    });
0.9.0

7 years ago

0.8.0

7 years ago

0.7.0

7 years ago

0.6.0

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago