Skip to content

itty-fetcher

GitHubVersionBundle SizeCoverage StatusNPM Weekly DownloadsDiscord

An ultra-tiny native fetch wrapper to clean up your API calls.

~650 bytes of pure magic to transform your fetch calls from verbose boilerplate into clean, readable API calls.

What is itty-fetcher?

itty-fetcher is a lightweight wrapper around the native fetch API that eliminates common boilerplate and provides a more intuitive way to make HTTP requests. Built with the same philosophy as other itty.dev libraries - maximum functionality with minimal bytes.

✨ Key Features

  • Automatic - JSON parsing, request serialization, error throwing, etc.
  • Composable - Set up your API/endpoint once, then call it cleanly
  • Human-Readable - Method calls that feel natural (api.get('/users'), users.post({ name: 'Steve' }))
  • 100% TypeScript - Intelligent type inference with generics for request/response shapes
  • Universal - Works everywhere fetch is supported... and everywhere it's not (through polyfills)

Quick Comparison

Before (native fetch):

ts
const response = await fetch('/api/users', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'Alice' })
})

if (!response.ok) throw new Error(`${response.status}: ${response.statusText}`)

const user = await response.json()

After (itty-fetcher):

ts
const user = await fetcher().post('/api/users', { name: 'Alice' })

Installation

bash
npm install itty-fetcher
# or
yarn add itty-fetcher
# or
bun add itty-fetcher

Basic Usage

ts
import { fetcher } from 'itty-fetcher'

// Simple requests
const users = await fetcher().get('/api/users')
const newUser = await fetcher().post('/api/users', { name: 'Alice' })

// Create a reusable API client
const api = fetcher('https://api.example.com', {
  headers: { 'Authorization': 'Bearer token' }
})

const data = await api.get('/users')

Philosophy

Like any itty.dev project, this is not a kitchen-sink library. If you need advanced features like automatic retries or complex request interception, consider a more full-featured library. This is for when you want native fetch behavior with dramatically less boilerplate.

✅ Perfect for:

  • Removing boilerplate from fetch calls
  • Projects using native fetch today
  • Composable API clients
  • Simple use-cases where size matters

❌ Consider alternatives for:

  • Automatic retries or timeout handling
  • GraphQL (use a GraphQL client)
  • Complex request/response middleware
  • Very advanced edge-cases

Next Steps