ts-rx-rest
RxJs Http client for Typescript.
Provides convenient typed wrappers for http verbs:
Install
$ npm install --save ts-rx-rest
Usage
import Rest, {errorInterceptor, jsonInterceptor, withCredentialsInterceptors} from 'ts-rx-rest';
const rest = new Rest()
.wrapRequest(withCredentialsInterceptors)
.wrap(errorInterceptor)
.wrap(jsonInterceptor);
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) {
}
});