ofetch
- Version 1.5.1
- Published
- 63.9 kB
- 3 dependencies
- MIT license
Install
npm i ofetchyarn add ofetchpnpm add ofetchOverview
A better fetch API. Works on node, browser and workers.
Index
Variables
Functions
Classes
Interfaces
Type Aliases
Variables
variable $fetch
const $fetch: $Fetch;variable AbortController
const AbortController: { new (): AbortController; prototype: AbortController };variable Headers
const Headers: { new (init?: HeadersInit): Headers; prototype: Headers };variable ofetch
const ofetch: $Fetch;Functions
function createFetch
createFetch: (globalOptions?: CreateFetchOptions) => $Fetch;function createFetchError
createFetchError: <T = any>(ctx: FetchContext<T>) => IFetchError<T>;function fetch
fetch: ( input: string | URL | Request, init?: RequestInit | undefined) => Promise<Response>;Classes
class FetchError
class FetchError<T = any> extends Error implements IFetchError<T> {}constructor
constructor(message: string, opts?: { cause: unknown });Interfaces
interface $Fetch
interface $Fetch {}property native
native: Fetch;method create
create: (defaults: FetchOptions, globalOptions?: CreateFetchOptions) => $Fetch;method raw
raw: <T = any, R extends ResponseType = 'json'>( request: FetchRequest, options?: FetchOptions<R>) => Promise<FetchResponse<MappedResponseType<R, T>>>;call signature
<T = any, R extends ResponseType = 'json'>( request: FetchRequest, options?: FetchOptions<R>): Promise<MappedResponseType<R, T>>;interface CreateFetchOptions
interface CreateFetchOptions {}property AbortController
AbortController?: typeof AbortController;property defaults
defaults?: FetchOptions;property fetch
fetch?: Fetch;property Headers
Headers?: typeof Headers;interface FetchContext
interface FetchContext<T = any, R extends ResponseType = ResponseType> {}interface FetchError
interface FetchError<T = any> extends IFetchError<T> {}interface FetchHooks
interface FetchHooks<T = any, R extends ResponseType = ResponseType> {}property onRequest
onRequest?: MaybeArray<FetchHook<FetchContext<T, R>>>;property onRequestError
onRequestError?: MaybeArray< FetchHook< FetchContext<T, R> & { error: Error; } >>;property onResponse
onResponse?: MaybeArray< FetchHook< FetchContext<T, R> & { response: FetchResponse<T>; } >>;property onResponseError
onResponseError?: MaybeArray< FetchHook< FetchContext<T, R> & { response: FetchResponse<T>; } >>;interface FetchOptions
interface FetchOptions<R extends ResponseType = ResponseType, T = any> extends Omit<RequestInit, 'body'>, FetchHooks<T, R> {}property agent
agent?: unknown;Only supported older Node.js versions using node-fetch-native polyfill.
property baseURL
baseURL?: string;property body
body?: RequestInit['body'] | Record<string, any>;property dispatcher
dispatcher?: InstanceType<typeof undici.Dispatcher>;Only supported in Node.js >= 18 using undici
See Also
https://undici.nodejs.org/#/docs/api/Dispatcher
property duplex
duplex?: 'half' | undefined;Set to "half" to enable duplex streaming. Will be automatically set to "half" when using a ReadableStream as body.
See Also
https://fetch.spec.whatwg.org/#enumdef-requestduplex
Modifiers
@experimental
property ignoreResponseError
ignoreResponseError?: boolean;property params
params?: Record<string, any>;Deprecated
use query instead.
property parseResponse
parseResponse?: (responseText: string) => any;property query
query?: Record<string, any>;property responseType
responseType?: R;property retry
retry?: number | false;property retryDelay
retryDelay?: number | ((context: FetchContext<T, R>) => number);Delay between retries in milliseconds.
property retryStatusCodes
retryStatusCodes?: number[];Default is [408, 409, 425, 429, 500, 502, 503, 504]
property timeout
timeout?: number;timeout in milliseconds
interface FetchResponse
interface FetchResponse<T> extends Response {}interface IFetchError
interface IFetchError<T = any> extends Error {}property data
data?: T;property options
options?: FetchOptions;property request
request?: FetchRequest;property response
response?: FetchResponse<T>;property status
status?: number;property statusCode
statusCode?: number;property statusMessage
statusMessage?: string;property statusText
statusText?: string;interface ResolvedFetchOptions
interface ResolvedFetchOptions<R extends ResponseType = ResponseType, T = any> extends FetchOptions<R, T> {}property headers
headers: Headers;interface ResponseMap
interface ResponseMap {}property arrayBuffer
arrayBuffer: ArrayBuffer;property blob
blob: Blob;property stream
stream: ReadableStream<Uint8Array>;property text
text: string;interface SearchParameters
interface SearchParameters {}index signature
[key: string]: any;Type Aliases
type Fetch
type Fetch = typeof globalThis.fetch;type FetchHook
type FetchHook<C extends FetchContext = FetchContext> = ( context: C) => MaybePromise<void>;type FetchRequest
type FetchRequest = RequestInfo;type GlobalOptions
type GlobalOptions = Pick<FetchOptions, 'timeout' | 'retry' | 'retryDelay'>;type MappedResponseType
type MappedResponseType< R extends ResponseType, JsonType = any> = R extends keyof ResponseMap ? ResponseMap[R] : JsonType;type ResponseType
type ResponseType = keyof ResponseMap | 'json';Package Files (2)
Dependencies (3)
Dev Dependencies (16)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/ofetch.
- Markdown[](https://www.jsdocs.io/package/ofetch)
- HTML<a href="https://www.jsdocs.io/package/ofetch"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3881 ms. - Missing or incorrect documentation? Open an issue for this package.
