Axios vs HttpClientModule
What's your take in using axios for angular query instead of httpclient of angular?
5 Replies
rising-crimson•8mo ago
Well, I would not even use the HttpClient of Angular for non angular query based angular app. I never understood whats the point of having an observable based http client when an http request is a single request/response pattern.
I personnaly use axios with Angular even though I'm not a huge fan of it too because it throws errors instead of returning them.
absent-sapphireOP•8mo ago
Exactly, it is a single request/response pattern.
hilarious-sapphire•8mo ago
Observables don't make a ton of sense for http requests as it's indeed a one off response, but they do make data mapping easy and rxjs has many operators available that might help, or add your own custom operators. Also
HttpClient
is very well integrated with the rest of the framework: supports server side rendering and transferring cache to client, unit testing is easy with provideHttpClientTesting
, supports interceptors, and you would benefit from any other features added to the framework in the future. All this nicely configurable through provideHttpClient
So I do in general recommend using Angular's HttpClient
with TanStack Query.
HttpClientModule is deprecated BTWplain-purple•8mo ago
Are there any plans to be able to return observables from
queryFn
? It's not a big deal but also writing lastValueFrom
every time feels messy. I'd be happy to provide any help to implement that feature, but I also feel like it's a bit out of my depth. I suspect it might be a bit challenging if someone passes an actual observable that can produce more than 1 value over time. I guess it's safe to assume that observables produced by HttpClient
return only 1 value.hilarious-sapphire•8mo ago
I did plan to, but not sure at this moment. If so, probably after a stable release. It's not at all difficult to support observables from
queryFn
- I got this working a long time ago. But getting all the typings right is.
@SergeyFilenko After thinking about this a bit I have some other ideas for supporting observables that would be more featureful and would keep the package types simpler and more maintainable. I'll add an issue with a proposal in the coming days so everybody can give feedback.