CodeVetter · Repo Unpack · Extension points
unjs/ofetch
Extension primarily happens through factories, typed options, and lifecycle hooks. Transport injection permits alternative fetch implementations without changing the request pipeline. Parsers and response mappings offer decoding customization, while dispatchers expose runtime-specific networking. Source-level helper tables define the narrower places where core behavior can be extended.
- CreateFetchOptions.fetch injects a fetch-compatible transport into createFetch, allowing tests or adapters to replace network execution.
- $fetch.create accepts shared defaults and custom global options, preserving inherited globals while new defaultOptions have final shallow precedence.
- FetchHooks defines four typed lifecycle interfaces; callHooks awaits array members sequentially using the same mutable context.
- parseResponse replaces JSON.parse after text consumption and takes precedence over responseType by selecting the JSON branch.
- ResponseMap and MappedResponseType centralize compile-time result mapping; adding response types requires coordinating these types with runtime decoding.
- retryStatusCodes and retryDelay permit application-specific retry selection and contextual delay calculation without modifying the built-in status set.
- FetchOptions can be augmented through TypeScript module declaration merging, with custom fields available to shared onRequest hooks.
- dispatcher and legacy agent options expose transport configuration; core payload-method and content-type sets are localized in utils.ts for source-level extensions.