Skip to content

itty-fetcher

GitHubVersionBundle SizeCoverage StatusNPM Weekly DownloadsDiscord

Fetch, without the boilerplate (and Typed).

Fetcher is an ultra-compact (~650 bytes) wrapper around native Fetch, designed purely to avoid boilerplate steps and shrink downstream code.

Fetcher allows this:

ts
const newUser = await fetcher().post<NewUser, User>('/api/users', { name: 'Alice' })

Instead of this:

ts
const newUser = await fetch('/api/users', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'Alice' })
}).then(response => {
  if (!response.ok) throw new Error(`${response.status}: ${response.statusText}`)

  return response.json()
})

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:

  • Simplifying data fetching/sending
  • Composable API clients
  • Saving bundle size (this pays for itself within a few calls)

❌ Consider alternatives for:

  • Automatic retries or timeout handling
  • GraphQL (use a GraphQL client)
  • VanillaJS purists (we applaud your unwavering resolve)
  • Streams?