An elegant fetch wrapper inspired by axios
and Rust's Result.
- ✅ Designed to work well with TanStack Query
- ✅ Response validation with StandardSchema (Zod, Arktype, ...)
- ✅ Typed HTTP responses & error union (
HttpResult<T>
) - ✅ Built-in timeout and abort controller
- ✅ Supports
FormData
, URL query (?query
) and parameters (/:id
)
λ bun add @zhaoworks/fetch
import { HttpClient } from '@zhaoworks/fetch';
export const http = new HttpClient({
endpoint: 'https://api.example.com',
headers: () => ({ Authorization: `Bearer ${getToken()}` }),
});
const result = await http.get<{ name: string; }>('/users/:id', {
params: { id: '123' },
});
if (!result.success) {
return console.error(result.error.message);
}
console.log(result.data.name);