TanStack Query (React Query): Handling HTTP Requests with EaseEntry 10 of 10

Summary

ConceptTanStack Query (React)Angular (built-in)
SetupQueryClient + <QueryClientProvider>provideHttpClient()
Read datauseQuery({ queryKey, queryFn })rxResource({ params, stream }) / httpResource()
Statedata, isPending, isLoading, isError, errorvalue(), isLoading(), error(), status()
Manual refetchrefetch()reload()
CacheQueryClient, keyed by queryKeyRoot service with signals
FreshnessstaleTimeTimestamp check in service
Cache cleanupgcTimeService lifetime
ParametersDynamic queryKeyparams signal
Cancellationsignal → fetchAutomatic (unsubscribe) / abortSignal
Conditionalenabledparams returns undefined
Write datauseMutation + mutate()Service call + subscribe()
After writeinvalidateQueries({ queryKey })Version signal / reload()
OptimisticonMutate + setQueryData + rollback in onErrorvalue.set() + rollback in error
Final resynconSettled → invalidateQueriesfinalize → reload()

TanStack Query turns server data into a shared, self-refreshing cache: queries read by key, mutations write and invalidate, and optimistic updates edit the cache directly with a rollback plan. Angular covers the same needs with built-in pieces: HttpClient services for requests, rxResource() for signal-based request state, and root services with signals when data must be shared, cached, or updated optimistically.