1.6.0 • Published 7 months ago

@maciekdev/fetcher v1.6.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

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

1.6.0

7 months ago

1.5.3

8 months ago

1.5.2

8 months ago

1.5.1

8 months ago

1.5.0

9 months ago

1.4.0

9 months ago

1.3.1

9 months ago

1.3.0

9 months ago

1.2.2

9 months ago

1.2.1

9 months ago

1.2.0

9 months ago

1.1.0

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

0.0.0-development

9 months ago

1.0.1

9 months ago

0.2.7

9 months ago

0.2.6

10 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago