Angular API Requests with tanstack-fetch and TanStack Query
How do you keep HTTP requests consistent across an Angular application without mixing API transport, server-state management, and UI logic?
One practical option is to use a dedicated HTTP client alongside TanStack Query.
In this tutorial, we'll build a small Angular users screen using tanstack-fetch.
tanstack-fetch is an independent open-source project by Mohammad Garmabi, not an official TanStack package.
Install
npm install tanstack-fetch
npm install @tanstack/angular-query-experimental
Create the client
// api.ts
import { createFetch } from 'tanstack-fetch';
export interface User {
id: number;
name: string;
email: string;
}
export const api = createFetch({
baseUrl: 'https://jsonplaceholder.typicode.com',
});
Provide it through Angular DI
import { bootstrapApplication } from '@angular/platform-browser';
import { provideFetchClient } from 'tansta
Discussion
Jump in and comment!
Get the ball rolling with your comment!