Angular 19.2 is here, and the standout feature is the experimental httpResource.
Previously, triggering an HTTP request based on a Signal change required using an `effect`. With Angular 19.0, `resource` provided a structured way to handle asynchronous data, but `httpResource` is the dedicated solution for handling HTTP requests in a reactive manner.
How does it work?
Instead of manually managing requests, `httpResource` integrates seamlessly with Signals. By passing one or multiple Signals into the url parameter, it automatically executes an HTTP request whenever their values change. The result is stored in a Signal, which is the `value` of `quiz` in the example.
`resource` and `rxResource` remain foundational for handling asynchronous tasks in Angular. HTTP requests make up the majority of such operations. That’s why `httpResource` is set to become the preferred tool for data fetching. Although 19.2 is a minor release, its impact is significant.
Key aspects of `httpResource`
*1. No replacement for `HttpClient`*
It is optimized for reactive data fetching but does not replace `HttpClient` for mutations (POST, PUT, DELETE).
*2. Eagerly/Pre-fetching as default behavior*
In contrast to Observables, which request lazily, i.e. upon subscription, httpResource fetches eagerly. So even before it is needed.
*3. `parse` built-in*
It introduces a more flexible approach to type handling, allowing the use of a parse function (e.g., with Zod) for runtime validation and stronger type safety.
*4. default value and no pre-fetching*
Developers can define default values, manually trigger requests, or delay execution by returning `undefined`. However, if the request resolves to `undefined`, `.reload()` will not function.
Beyond 19.2: The Future of Resources
Alongside the release, the Angular team published two RFCs. The first discusses the motivation behind resource, alternative approaches (such as suspense-based handling), and potential future integrations, including routing, SSR, and error handling.
The second RFC details the API design for `resource`, `rxResource`, and `httpResource`. The team is actively seeking feedback (just saying).
There is already extensive community coverage of `httpResource`, with some of it featured in previous episodes. However, for a deeper understanding, the RFCs remain the primary reference.
RFC 1: https://github.com/angular/angular/di...
RFC 2: https://github.com/angular/angular/di...