@zhaoworks/fetch
v1.3.3
Published
an elegant fetch wrapper.
Readme
— @zhaoworks/fetch
An elegant fetch wrapper inspired by axios and Rust's Result.
Features
- ✅ 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)
Installation
λ bun add @zhaoworks/fetchUsage
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);