Relative Content

Tag Archive for angulartypescriptrxjsangular-promiseangular-signals

Angular HttpClient calls and signals

I am diving deep into signals watching tutorials and reading articles. When calling an api endpoint with httpClient I’ve seen two main approaches (at least that I liked) and I am unable to find much online that compares the two. The first one is to have a service with a function that makes the endpoint call with httpClient, handles errors with RxJs operators, then the response is transformed into a signal. The calling component gets back the response as a signal. So basically transforming the response into a signal and error handling is done by the service. The second approach is to have the service make the endpoint call with httpClient in a function that uses async/await and returns a promise. The calling component will also have an async await function with a try-catch block, this function gets the promise and sets the response to a signal. So basically the service just gets the data and sends it to the caller as a promise, the calling component handles the errors and assigns the data to a signal. Thoughts? Ideas? comments? mix both? other approaches?