A lightweight and simple fetch wrapper for Node.js and potentially the browser.
Fetcher provides a minimal and straightforward way to make HTTP requests using the familiar fetch
API. It aims to simplify common use cases without adding unnecessary complexity.
- Lightweight: Minimal dependencies and a small footprint.
-
Simple API: Mirrors the standard
fetch
API for ease of use. - TypeScript Support: Written in TypeScript with type definitions included.
pnpm add @maciekdev/fetcher
# or
npm install @maciekdev/fetcher
# or
yarn add @maciekdev/fetcher
# or
bun add @maciekdev/fetcher
import { z } from "zod/v4";
import { createFetcherInstance } from "@maciekdev/fetcher";
export const fetcher = createFetcherInstance({
baseURL: "https://myfabulousAPI.test",
});
const zodSchema = z.object({
username: z.string(),
});
const myData = await fetcher({
method: "GET",
url: "/test-endpoint",
schema: zodSchema,
});
console.log(myData?.username);
/*
username: string | undefined
Typesafe!
*/
Parameters:
-
options
?: (FetcherInstanceOptions) Configuration object for fetcher instance.
Parameters:
-
options
?: (FetcherOptions) Configuration object for fetcher instance.
Options config:
-
responseType
?: "json" | "text" | "arrayBuffer"; -
method
: "GET" | "POST" | "DELETE" | "PUT" | "PATCH"; -
url
: string; -
body
?: FormData | Record<string, unknown>; -
schema
?:zodSchema
; -
throwOnError
?: boolean; -
signal
?: AbortSignal; -
headers
?: Record<string, string>;
MIT