@cmss/http-client-rxjs
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

httpModule

httpModule是由Angular的httpClient模块打包的网络请求库。Angular的httpClient模块采用了typescript和Rx.js。使用httpModule要用函数式的方式,如果用上Rx.js丰富的操作符,可以写出十分简洁明了的代码。

基本用法

// http配置
const httpOptions = {
  headers: {
    'Content-Type': 'application/json'
  }
};

let http = new RestClient(httpOptions);

// 发起请求
http.get(url).subscribe(value => {
  ...
})

错误处理

import { throwError } from 'rxjs';
import { retry, catchError } from 'rxjs/operators';

const handleError = (error) => {
  ...
  // 返回一个 observable 用于 rxjs catch 处理,方便用户自定义 catch 处理方式。
  return throwError('Something bad happened; please try again later.');
}

http.get(url).pipe(
  retry(3),
  catchError(handleError)
).subscribe(value => {
  ...
})

/@cmss/http-client-rxjs/

    Package Sidebar

    Install

    npm i @cmss/http-client-rxjs

    Weekly Downloads

    1

    Version

    1.0.0

    License

    none

    Unpacked Size

    299 kB

    Total Files

    63

    Last publish

    Collaborators

    • lucas_tsai
    • honghuajian
    • denghuijie
    • fy912731073
    • dyh333
    • jkhhuse
    • yangjingjingqing