What you will learn
Load typed remote data and represent loading, success, empty, and failure states.
- Provide HttpClient once with provideHttpClient. A service should describe request and response types instead of passing unknown objects through the UI.
- Interceptors handle cross-cutting request concerns such as an application header or consistent error logging. Never place a private server secret in browser code.
- Every request UI needs explicit loading, error, empty, and success states. Cancellation matters when a new query makes an older response irrelevant.
- Angular's signal resource APIs can model asynchronous state for signal-based code; HttpClient remains appropriate for HTTP, interceptors, progress, and established RxJS flows.
How it works
1Component requests data
2Interceptor adds public metadata
3Backend responds
4UI handles every state
Expected result
Requests to /api/students include the public X-Client header and return a typed observable. The example requires a matching backend endpoint.
Common mistakes
Do not expose secrets in an interceptor. Do not subscribe repeatedly without understanding lifetime. Check backend authorization and validation independently from the UI.
