Sending HTTP Requests (e.g. Connecting to a Database)Entry 7 of 7

Summary

ConceptReactAngular
Fetch on mountfetch in useEffect(..., [])httpResource() / HttpClient in ngOnInit
Loading and error stateSeparate useState valuesisLoading(), error(), value()
HTTP error detectionCheck response.ok manuallyAutomatic for non-2xx
JSON body and headersManualAutomatic
Where HTTP code livesOften the component; optionally an API moduleInjectable service (the convention)
Cross-cutting logicWrapper around fetchInterceptors
Send dataEvent handler + fetchService method + HttpClient
Optimistic updatesetState + rollback in catchsignal.set() + rollback in error
Cancel stale requestsAbortController in cleanuphttpResource() / switchMap

React gives you the browser's fetch and leaves loading, errors, cancellation, and code organization to you (or to a library); fetching inside components is common. Angular places HTTP calls in services by convention, and its HttpClient and httpResource() build most of the rest in.