Difference between Cold or Hot http requests?

2019-02-18 18:37发布

Could somebody explain me two things:

  • Difference between Cold or Hot http requests?
  • Are http requests in Angular 2 Cold or Hot?

2条回答
可以哭但决不认输i
2楼-- · 2019-02-18 19:27

In Angular, http requests made from the Http service are cold.

Cold, in this context, means that the http request is not made until someone subscribes to the observable returned from Http.get, Http.post etc. Also, each subscription to an http observable will cause a different http request to be fired. This is because, as a cold observable, the http observable is responsible for creating its producer (i.e. the Ajax request) on subscription, and each subscription will create a separate producer of values (i.e. separate Ajax requests).

Thoughtram has a detailed article on hot vs cold observables.

查看更多
我只想做你的唯一
3楼-- · 2019-02-18 19:38

Its cold since any request only starts producing value first when you subscribe to it. Without running

http.get().subscribe((response) => ...)

No request will be send to the server. http.get() alone is just an object.

查看更多
登录 后发表回答