Add Support for Observable (as opposed to Promise)
See original GitHub issueFeature Description Axios is currently promise based library. It would be great that if it also support observable. Two great benefits of using observables:
- leveraging rxjs operator
- cancel http request through
unsubscribe
(as opposed to cancel token)
Existing Solutions
I have implemented a library axios-observable
(https://www.npmjs.com/package/axios-observable). It’s basically a thin wrapper around axios
with almost the same API as axios
.
It also enables cancelling http request through unsubscribe - a more straightforward way than using cancel token.
Proposals
I am thinking if we can incorporate axios-observable
into axios
to make observable officially supported. If you guys are very positive about this idea, I will be very happy to make an PR.
Happy to discuss.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:5 (1 by maintainers)
Top Results From Across the Web
When to use Promise over observable? - Stack Overflow
An observable does everything that a promise does and more. It can always be switched to a promise with toPromise() method in case...
Read more >Angular Observable vs. Promise & How to Create Them
Something to remember is that Angular Promise is more passive compared to the Observable and cannot be cancelled once it is started. In...
Read more >Promise vs Observable in Angular with (.subscribe, .then , .pipe).
A Promise is not lazy where as an Observable is Lazy. Let's prove this with an example. Consider this method getEmployeeByCode() in employee....
Read more >Observables compared to other techniques - Angular
Observables are often compared to promises. Here are some key differences: Observables are declarative; computation does not start until subscription.
Read more >JavaScript Promises vs. RxJS Observables - Auth0
The best thing about Promises is that they come built-in with JavaScript. That means we don't have to add anything to our package...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Interesting idea and concept. To be completely honest, I don’t see axios implementing observables in the short run at least, your library seems pretty cool and I think the best way for us to move forward is with separate libraries to keep each one small and let developers decide which pattern to follow.
Open to other ideas, these are just my first impressions, I’ll let others share their opinions as well
HI,
Thanks for submitting this I don’t think that this is something that Axios will implement any time soon.
Thanks