Overview
ofetch provides several type definitions for handling different response formats and type-safe response parsing.ResponseType
The available response types that ofetch can parse."json"- Parse response as JSON (default)"text"- Return response as text string"blob"- Return response as Blob"arrayBuffer"- Return response as ArrayBuffer"stream"- Return response as ReadableStream
ResponseMap
Maps response type strings to their corresponding TypeScript types.responseType.
MappedResponseType
Utility type that maps a response type string to its corresponding TypeScript type.The response type string
The TypeScript type to use for JSON responses
FetchResponse
Extends the standardResponse interface with an additional _data property containing the parsed response data.
HTTP status code (e.g., 200, 404)
HTTP status message (e.g., “OK”, “Not Found”)
True if status is in the range 200-299
Response headers
Final URL of the response (after redirects)
True if the response is the result of a redirect
Type of response (basic, cors, error, etc.)
Response body stream
Parsed response data. The type depends on the
responseType option.FetchContext
Context object passed to lifecycle hooks containing request, options, response, and error information.The request URL string or Request object
Resolved fetch options with headers as a Headers object. See FetchOptions.
The response object if available. Present in
onResponse and onResponseError hooks.Error object if an error occurred. Present in
onRequestError hook.ResolvedFetchOptions
FetchOptions with headers guaranteed to be a Headers object.options property, ensuring headers are always in a consistent format.
Type Parameters
The expected type of the response data
The response type:
"json", "text", "blob", "arrayBuffer", or "stream"Related
- FetchOptions - Request configuration options
- FetchHooks - Lifecycle hooks that use FetchContext
- ofetch.raw() - Returns FetchResponse