Also, usage of Observable should be done if you are working on subscription of data. If you are hitting service only once to get REST data then there is no sense to have Observable subscription.

Actually there are quite a few reasons to use observables instead of promises even for single response endpoints:

  • Consistency
  • Easier map-reduce actions
  • The ability to cancel in-flight requests with subscription.unsubscribe(), switchMap, etc.

The classical example being an autocomplete control. The user keeps pressing keys and we send multiple requests to an endpoint. However, we are only ever interested in the response of the request that was sent last. switchMap handles this nicely for us.

Lars Gyrup Brink Nielsen

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade