CodeVetter · Repo Unpack · Feature catalog
unjs/ofetch
The user-facing surface is an HTTP client API with typed options and results. Automatic serialization and decoding remove common fetch boilerplate. Factories and hooks support shared application behavior, while retry and timeout options control failures. Raw responses, streams, and transport dispatchers expose lower-level capabilities.
- $fetch returns decoded _data, raw returns the augmented Response, and native delegates directly to the captured fetch transport.
- Response decoding supports JSON, text, blob, arrayBuffer, and stream; parseResponse supplies a custom synchronous parser of response text.
- Payload handling serializes eligible objects, preserves strings, selects URL-encoded serialization for the exact form content type, and supplies missing JSON headers.
- FormData and URLSearchParams bypass JSON classification, while web and Node stream bodies automatically receive duplex half unless explicitly configured.
- String requests support baseURL and query parameters; params remains a deprecated alias, with values merged from defaults and individual calls.
- Users can configure retry count, eligible status codes, fixed or contextual delay, timeout milliseconds, and suppression of HTTP status errors.
- Four lifecycle hooks accept functions or arrays, and create builds reusable clients with shared options and optional custom transport.
- Node transport customization includes an undici dispatcher option; documentation demonstrates ProxyAgent, SSE stream consumption, and FetchOptions augmentation.