@maciekdev/fetcher
TypeScript icon, indicating that this package has built-in type declarations

1.6.0 • Public • Published

Fetcher

A lightweight and simple fetch wrapper for Node.js and potentially the browser.

NPM Version License spring-easing's badge

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.

Features

  • 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.

Installation

pnpm add @maciekdev/fetcher
# or
npm install @maciekdev/fetcher
# or
yarn add @maciekdev/fetcher
# or
bun add @maciekdev/fetcher

Example usage

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!
*/

API reference

createFetcherInstance(options | undefined)

Parameters:

  • options?: (FetcherInstanceOptions) Configuration object for fetcher instance.

fetcher(options)

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

License

MIT

Package Sidebar

Install

npm i @maciekdev/fetcher

Weekly Downloads

20

Version

1.6.0

License

MIT

Unpacked Size

85.2 kB

Total Files

32

Last publish

Collaborators

  • maciekdev