upfetch
Original:🇺🇸 English
Translated
Load this skill for any up-fetch task: `up(fetch, getDefaultOptions?)`, `upfetch(url, options?)`. Covers dynamic defaults, auth, request shaping, validation, error handling, lifecycle timing, and runtime caveats.
18installs
Sourcel-blondy/up-fetch
Added on
NPX Install
npx skill4agent add l-blondy/up-fetch upfetchTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →upfetch
Use when you need a reusable fetch client with request-scoped defaults, automatic request/response shaping, runtime validation, retries, and lifecycle hooks.
up-fetchMental model
- creates the reusable client.
up(fetchFn, getDefaultOptions?) - runs on every request.
getDefaultOptions(input, options, ctx) - performs one request.
upfetch(input, options?, ctx?) - Keep high-level; load the relevant file under
SKILL.mdfor details.references/
Minimum pattern
ts
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 , not a plain object.
up() - Read auth and other mutable defaults inside that function so values stay fresh.
- Use and
paramsinstead of hand-serializing query strings or JSON.body - Use when you need runtime trust; TypeScript generics alone do not validate payloads.
schema - If you want error-as-value behavior, set before relying on
reject: () => false.parseResponse - Prefer over imported
globalThis.fetch.undici.fetch
References
- Client setup and dynamic defaults
- Auth and request shaping
- Validation, parsing, and errors
- Retries, timeouts, and lifecycle
- Streaming and runtime caveats