Overview
ofetch is the main function exported by the library. It provides a modern, type-safe interface for making HTTP requests with automatic response parsing, error handling, and retry logic.
The $fetch alias is also available and functionally identical to ofetch.
Type Signature
Usage
Basic Request
FetchRequest
required
The URL or Request object to fetch
FetchOptions<R>
Request options and configuration. See FetchOptions for details.
Promise<MappedResponseType<R, T>>
Returns a promise that resolves to the parsed response data based on the
responseTypeMethods
ofetch()
The main function that returns parsed response data.FetchRequest
required
URL string or Request object
FetchOptions<R>
Request configuration options
Promise<MappedResponseType<R, T>>
Parsed response data (JSON by default)
ofetch.raw()
Returns the full Response object with parsed data available in_data property.
FetchRequest
required
URL string or Request object
FetchOptions<R>
Request configuration options
Promise<FetchResponse<MappedResponseType<R, T>>>
Full Response object with
_data property containing parsed response. See FetchResponse.ofetch.native()
Access to the nativefetch function used internally.
Parameters<typeof globalThis.fetch>
Standard fetch API arguments
Promise<Response>
Native fetch Response object
ofetch.create()
Create a newofetch instance with custom default options.
FetchOptions
required
Default options to apply to all requests made with this instance. See FetchOptions.
CreateFetchOptions
Global configuration options. See createFetch.
$Fetch
A new ofetch instance with the provided defaults
Type Parameters
any
default:"any"
The expected type of the response data
ResponseType
default:"json"
The response type:
"json", "text", "blob", "arrayBuffer", or "stream". See ResponseType.Related Types
- FetchOptions - Request configuration options
- FetchResponse - Response interface
- ResponseType - Available response types
- CreateFetchOptions - Instance creation options