Skip to content

zhaoworks/fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

— @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/fetch

Usage

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);

License

MIT

About

a ease-to-use wrapper around the Fetch API. (designed for frontends)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •