About upfetch
upfetch is a guide to using a reusable fetch client, for TypeScript developers who need request defaults, validation, and lifecycle handling. It covers request and response shaping, retries, timeouts, and hooks, with further references organized by topic.
Key features
- 01Set dynamic request-scoped defaults
- 02Shape authentication, parameters, and request bodies
- 03Validate data at runtime with schemas
- 04Configure response parsing and error handling
- 05Handle retries, timeouts, and lifecycle hooks
Use cases
- 01Reuse base URLs and headers across API requests
- 02Validate the structure of server responses
- 03Add retry and timeout behavior to requests
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ l-blondy/ up-fetch --skill upfetchAfter installing, type/upfetchin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
references/auth-and-request-shaping.mdclient-setup-and-dynamic-defaults.mdretries-timeouts-and-lifecycle.mdstreaming-and-runtime-caveats.mdvalidation-parsing-and-errors.mdDetails
From the project READMEupfetch
Use up-fetch when you need a reusable fetch client with request-scoped defaults, automatic request/response shaping, runtime validation, retries, and lifecycle hooks.
Mental model
up(fetchFn, getDefaultOptions?)creates the reusable client.getDefaultOptions(input, options, ctx)runs on every request.upfetch(input, options?, ctx?)performs one request.- Keep
SKILL.mdhigh-level; load the relevant file underreferences/for details.
Minimum pattern
import { up } from 'up-fetch'
import { z } from 'zod'
export const upfetch = up(fetch, () => ({
baseUrl: 'https://api.example.com',
headers: {
Authorization: readToken() ? `Bearer ${readToken()}` : undefined,
},
timeout: 5000,
}))
const user = await upfetch('/users/1', {
schema: z.object({
id: z.number(),
name: z.string(),
}),
})
Workflow
- Start with client setup and dynamic defaults.
- If the request needs auth, params, body shaping, or merge semantics, read auth and request shaping.
- If the response contract matters, read validation, parsing, and errors.
- If retries, timeouts, or hook timing matter, read retries, timeouts, and lifecycle.
- If streaming or runtime quirks matter, read streaming and runtime caveats.
High-value rules
- Pass a function as the second argument to
up(), not a plain object. - Read auth and other mutable defaults inside that function so values stay fresh.
- Use
paramsandbodyinstead of hand-serializing query strings or JSON. - Use
schemawhen you need runtime trust; TypeScript generics alone do not validate payloads. - If you want error-as-value behavior, set
reject: () => falsebefore relying onparseResponse. - Prefer
globalThis.fetchover importedundici.fetch.
References
Comments
Markdown supported