What is the resource API (and httpResource) in Angular, and how does it compare with using HttpClient and RxJS?
Model answer
The resource APIs bring async data into the signal world: a resource has a request that depends on signals and a loader, and it exposes signals such as value, status, error and isLoading, and reloads when its inputs change. httpResource does the same for HTTP calls.
They aim to make loading data and showing its state simpler than hand-written RxJS. They are newer and their stability has changed between versions, so check the Angular documentation for your version before relying on them, and keep HttpClient with RxJS for complex streams.
Tips
- Say that you check version status in the docs.
Learn this topic
Angular Tutorial: Beginner to Advanced .
Sign in to add your own answer.
More questions
- How do you call an API in Angular?
- What is an Observable, and how is it different from a Promise?
- What is the difference between subscribe and the async pipe?
- What are common RxJS operators you use, and what do they do?
- Explain the difference between switchMap, mergeMap, concatMap and exhaustMap.
- What are HTTP interceptors, and what are they used for?