Skip to content

adrian-bueno/fetchquack

Repository files navigation

fetchquack

fetchquack

npm version License: MIT

A lightweight, universal HTTP client built on the standard Fetch API. First-class support for streaming, Server-Sent Events (SSE), and progress tracking.

Works on Browser, Node.js 18+, Bun, Deno, and Angular 17+.

Features

  • Streaming — Text and binary streaming with chunk-by-chunk processing
  • Server-Sent Events — Full SSE spec with auto-reconnect and Last-Event-ID
  • Progress Tracking — Upload and download progress on all platforms
  • Interceptors — Middleware system with built-in auth, logging, CSRF, and header interceptors
  • Angular Integration — RxJS Observable wrapper with dependency injection support
  • TypeScript — Complete type definitions with generics
  • Zero Dependencies — ~4KB minified + gzipped

Installation

npm install fetchquack

Quick Start

import { HttpClient } from 'fetchquack';

const client = new HttpClient();

// JSON request
const user = await client.fetch<User>({
  method: 'GET',
  url: '/api/users/1'
});

// Streaming
const controller = new AbortController();

client.fetchStream({
  method: 'POST',
  url: '/api/ai/chat',
  body: { prompt: 'Hello!' },
  signal: controller.signal,
  decodeToString: true,
  onData: (chunk) => console.log(chunk),
  onComplete: () => console.log('Done')
});

// Server-Sent Events
client.sse({
  method: 'GET',
  url: '/api/events',
  signal: controller.signal,
  autoReconnect: true,
  onEvent: (event) => console.log(event.data)
});

Documentation

Read the full documentation

Runtime Compatibility

Runtime Version
Browser Modern browsers
Node.js 18.0+
Bun 1.0+
Deno 1.11+

Testing

See README-tests.md for testing documentation.

Contributing

Contributions are welcome! Please fork the repository, create a feature branch, and open a pull request.

License

MIT © Adrián Bueno Jiménez