Framework guidesAngular HttpClient vs tanstack-fetch for TanStack Query
Replace Angular HttpClient glue with tanstack-fetch: provideFetchClient, injectFetch, SSE as signals, Angular Query, refresh tokens and the migrate CLI.
Read the postOctober 12, 2026 · Vue · TanStack Query · HTTP

Stack
Vue 3.3+ · tanstack-fetch/vue · @tanstack/vue-query
In a Vue 3 app, ofetch or axios usually hides behind a hand-written composable that unwraps responses and converts errors before Vue Query ever sees them — and that composable gets copied into every project.
tanstack-fetch gives Vue the same client as React — via createFetchPlugin + useFetch composables.
| If you need… | Prefer |
|---|---|
Drop into useQuery / useMutation | tanstack-fetch |
Typed FetchError | tanstack-fetch |
SSE + Authorization | useSse from tanstack-fetch/vue |
| Simple script without Query | ofetch is fine |
| Share client with React/Nuxt | tanstack-fetch |
npm install tanstack-fetch vue @tanstack/vue-queryofetch returns the body on success but error shapes differ from Query’s expectations. axios still wants .data. One client should do both REST and SSE.
Contract that matters for Query:
isError works)signal throughimport axios from 'axios'
import { useQuery } from '@tanstack/vue-query'
const { data, error, isPending } = useQuery({
queryKey: ['users'],
queryFn: async ({ signal }) => {
const res = await axios.get<User[]>('/users', { signal })
return res.data
},
})import { createApp } from 'vue'
import { createFetch } from 'tanstack-fetch'
import { createAuthInterceptor } from 'tanstack-fetch/plugins'
import { createFetchPlugin } from 'tanstack-fetch/vue'
import { VueQueryPlugin } from '@tanstack/vue-query'
import App from './App.vue'
const api = createFetch({
baseUrl: import.meta.env.VITE_API_URL,
interceptors: [createAuthInterceptor({ getToken: () => localStorage.getItem('access_token') })],
})
createApp(App)
.use(createFetchPlugin({ client: api }))
.use(VueQueryPlugin)
.mount('#app')<script setup lang="ts">
import { useFetch } from 'tanstack-fetch/vue'
import { useQuery } from '@tanstack/vue-query'
import { isFetchError } from 'tanstack-fetch'
const api = useFetch()
const { data, error, isPending } = useQuery({
queryKey: ['users'],
queryFn: ({ signal }) => api.get<User[]>('/users', { signal }),
})
</script>
<template>
<p v-if="isPending">Loading…</p>
<p v-else-if="isFetchError(error)">{{ error.status }}</p>
<ul v-else>
<li v-for="u in data" :key="u.id">{{ u.name }}</li>
</ul>
</template>Pass createFetch options straight into createFetchPlugin({ baseUrl, getToken, … }) if you do not want a separate api module.
In Nuxt, rename when useFetch clashes: import { useFetch as useFetchClient } from 'tanstack-fetch/vue'.
Rough relative boilerplate (lower is better) — a map of where teams spend time, not a micro-benchmark.
tanstack-fetchtypical ofetch / axios path
| Capability | tanstack-fetch | ofetch / axios |
|---|---|---|
| Returns body for Query | Yes | Adapt |
| Typed error + status | FetchError | Partial |
| AbortSignal | First-class | Yes / vary |
| Status handlers | createStatusInterceptor | Custom |
| Refresh single-flight | Plugin | Custom |
Path params :id | Yes | Manual |
| SSE + Authorization | Yes | No |
| Vue composables | useFetch / useSse | DIY |
| Bundle | 3.68KB gzip | Small–medium |
import { createFetch } from 'tanstack-fetch'
import {
createAuthInterceptor,
createRefreshTokenInterceptor,
createStatusInterceptor,
} from 'tanstack-fetch/plugins'
let expiresAt = 0
const api = createFetch({
baseUrl: '/api',
interceptors: [
createAuthInterceptor({ getToken: () => localStorage.getItem('access_token') }),
createStatusInterceptor({ 403: () => toast.error('Forbidden') }),
],
})
api.use(
'refresh-token',
createRefreshTokenInterceptor({
refresh: async () => {
const body = await api.post<{ accessToken: string; expiresIn: number }>('/auth/refresh', {
interceptors: { eject: ['refresh-token', 'auth'] },
})
localStorage.setItem('access_token', body.accessToken)
expiresAt = Date.now() + body.expiresIn * 1000
},
before: { getExpiresAt: () => expiresAt, skewMs: 60_000 },
after: { enabled: true },
}),
)The plugin keeps one in-flight refresh and retries the failed call — the usual interceptor queue, without the queue code.
import { useMutation, useQueryClient } from '@tanstack/vue-query'
import { useFetch } from 'tanstack-fetch/vue'
const api = useFetch()
const queryClient = useQueryClient()
const createUser = useMutation({
mutationFn: (input: CreateUserInput) => api.post<User>('/users', { body: input }),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['users'] }),
})Browser EventSource cannot set Authorization. tanstack-fetch/sse streams over fetch.
<script setup lang="ts">
import { createFetch } from 'tanstack-fetch/sse'
import { useSse } from 'tanstack-fetch/vue'
const api = createFetch({ plugins: ['sse-resume'] })
const { data, status, error, close } = useSse<OrderEvent>('/orders/stream', { client: api })
</script>
<template>
<p v-if="status === 'error'">{{ error?.message }}</p>
<div v-else>
<p>{{ status }}</p>
<pre>{{ data }}</pre>
<button type="button" @click="close">Stop</button>
</div>
</template>Refs unwrap in the template. Plugin is optional when you pass { client }.
Status: connecting | connected | disconnected | error.
import { createTRPCClient, httpBatchLink } from '@trpc/client'
import { createTRPCFetch } from 'tanstack-fetch/trpc'
import { useQuery } from '@tanstack/vue-query'
import { api } from './api'
import type { AppRouter } from './server'
export const trpc = createTRPCClient<AppRouter>({
links: [httpBatchLink({ url: '/api/trpc', fetch: createTRPCFetch(api) })],
})
const posts = useQuery({
queryKey: ['posts'],
queryFn: ({ signal }) => trpc.post.list.query(undefined, { signal }),
})npx tanstack-fetch migrate --from ofetch --framework vue --write
# or
npx tanstack-fetch migrate --from axios --framework vue --write
npx tanstack-fetch doctor --dir ./srcsrc/
main.ts # createFetchPlugin + VueQueryPlugin
lib/api.ts
queries/users.ts
components/UsersList.vue
components/OrdersLive.vuetanstack-fetchtanstack-fetch/sse + useSsecreateFetch across packagescreateFetchPlugin registered{ signal } in every queryFnisFetchError for status UItanstack-fetch/ssenpm install tanstack-fetch vue @tanstack/vue-query
npx tanstack-fetch doctor --dir ./srcSame deep-dive format for every stack:
Framework guides·4 min read
Replace Angular HttpClient glue with tanstack-fetch: provideFetchClient, injectFetch, SSE as signals, Angular Query, refresh tokens and the migrate CLI.
Framework guides·3 min read
Replace Nuxt $fetch glue with tanstack-fetch — createFetchPlugin, ssr-forward, useFetchClient naming, Vue Query hydrate, SSE, and comparison graphs.
Framework guides·3 min read
Replace axios unwrap glue with tanstack-fetch — FetchProvider, useFetch, useSse, React Query, refresh-token, migrate CLI, and a full side-by-side comparison.