Fetcher
is a utility class for making HTTP requests with various data formats (text, JSON, Blob, FormData, ArrayBuffer). It provides a unified interface for handling requests and responses, ensuring consistency and reusability across your codebase.
HTTPError
for HTTP errors and ZodError
for schema validation errors.npm install @shrimpcoder/ts-fetcher
Fetcher
supports integration with Zod. You can use Zod schemas to validate responses.
[!Note] You are not required to use Zod schemas.
If no Zod schema is specified, the response will be returned asunknown
.
npm install zod
import { Fetcher } from '@shrimpcoder/ts-fetcher';
import { URLBuilder } from '@shrimpcoder/ts-fetcher';
import { z } from 'zod';
const urlBuilder = new URLBuilder({ baseUrl: 'https://api.example.com' });
const schema = z.object({ name: z.string() });
await Fetcher.get(urlBuilder, schema); // {name: string}
await Fetcher.get(urlBuilder); // unknown
For detailed usage, please refer to here.
This project is licensed under the MIT License.