Sending HTTP Requests (e.g. Connecting to a Database)Entry 7 of 7
Summary
| Concept | React | Angular |
|---|---|---|
| Fetch on mount | fetch in useEffect(..., []) | httpResource() / HttpClient in ngOnInit |
| Loading and error state | Separate useState values | isLoading(), error(), value() |
| HTTP error detection | Check response.ok manually | Automatic for non-2xx |
| JSON body and headers | Manual | Automatic |
| Where HTTP code lives | Often the component; optionally an API module | Injectable service (the convention) |
| Cross-cutting logic | Wrapper around fetch | Interceptors |
| Send data | Event handler + fetch | Service method + HttpClient |
| Optimistic update | setState + rollback in catch | signal.set() + rollback in error |
| Cancel stale requests | AbortController in cleanup | httpResource() / 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.