HttpClientModule 和 使用RxJS来处理常用的Http请求

HttpClientModule 是现有的 HttpModule的改进版,是 angular v4.30版本新增的模块,增加了一些新的功能,比如拦截器progress events等等

新的HttpClientModule位于:

import { HttpClietModule } from '@angular/commom/http'

具体的文章参考:

  1. The Angular HTTP Client - Quickstart Guide - angular university
  • 使用 RxJS新操作符ShareReplay() 避免重复的请求
  • 使用 RxJS操作符forkJoin()将多个http请求合并
  • 使用 RxJS操作符SwitchMap() 将第一次请求的结果作为第二次请求的一部分
  • 使用 RxJS操作符SwitchMap() 将多次请求的结果都保留下来, 关于SwitchMap的用法可以参考 Deep Dive Into The RxJs switchMap Operator - How Does it Work ? A Less Well-Known Use Case (selector functions) 这篇文章
  • 使用 RxJS操作符catch() 进行异常错误处理
  1. A Taste From The New Angular HTTP Client HttpClient的一些特点简介
  • JSON as default
  • Interceptors Support
  • Progress events
  1. Introduction to Angular's HttpClient 很精简的介绍

  2. Angular Authentication: Using the Http Client and Http Interceptors - 使用 HttpClient 实现验证拦截,很详细的教程,使用到了 angular-jwt

  3. The New HTTP Client in Angular 4.3 如何从HttpModule 升级到 HttpClientModule 模块

  4. JWT Interceptor with Angular HttpClient jwt中使用拦截器

  5. The new Angular HttpClient API

当然第一篇文章更加的详细

你可能感兴趣的:(HttpClientModule 和 使用RxJS来处理常用的Http请求)