Interface FfetchBaseOptions<Addons>

interface FfetchBaseOptions<
    Addons extends FfetchAddon<any, any>[] = FfetchAddon<any, any>[],
> {
    addons?: Addons;
    baseUrl?: string;
    body?: BodyInit;
    captureStackTrace?: boolean;
    extra?: RequestInit;
    fetch?: {
        (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
        (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
        (input: string | Request | URL, init?: RequestInit): Promise<Response>;
    };
    headers?: HeadersInit;
    json?: unknown;
    method?: | string & {}
    | "GET"
    | "POST"
    | "PUT"
    | "DELETE"
    | "PATCH"
    | "HEAD"
    | "OPTIONS"
    | "CONNECT";
    middlewares?: FfetchMiddleware[];
    readBodyOnError?: boolean;
    validateResponse?: false
    | (res: Response) => boolean | Promise<boolean>;
}

Type Parameters

Hierarchy (View Summary)

Properties

addons?: Addons

addons for the request

baseUrl?: string

base url to be prepended to the url

this base url is always treated as a "base path", i.e. the path passed to ffetch() will always be appended to it (unlike the new URL(), which has ambiguous slash semantics)

body?: BodyInit

body to be passed to fetch()

captureStackTrace?: boolean

whether to capture stack trace for errors may slightly impact performance

true
extra?: RequestInit

any additional options to be passed to fetch()

fetch?: {
    (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
    (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
    (input: string | Request | URL, init?: RequestInit): Promise<Response>;
}

implementation of fetch()

Type declaration

    • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
    • Parameters

      • input: RequestInfo | URL
      • Optionalinit: RequestInit

      Returns Promise<Response>

    • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
    • Parameters

      • input: RequestInfo | URL
      • Optionalinit: RequestInit

      Returns Promise<Response>

    • (input: string | Request | URL, init?: RequestInit): Promise<Response>
    • Parameters

      • input: string | Request | URL
      • Optionalinit: RequestInit

      Returns Promise<Response>

headers?: HeadersInit

headers to be passed to fetch()

json?: unknown

shorthand for sending json body. mutually exclusive with body

method?:
    | string & {}
    | "GET"
    | "POST"
    | "PUT"
    | "DELETE"
    | "PATCH"
    | "HEAD"
    | "OPTIONS"
    | "CONNECT"

http method

'GET'
middlewares?: FfetchMiddleware[]

middlewares for the requests

readBodyOnError?: boolean

whether to read the body of the response on HttpError (i.e. when validateResponse returns false). useful for debugging, but may be undesirable in some cases.

true
validateResponse?: false | (res: Response) => boolean | Promise<boolean>

whether to throw HttpError on non-2xx responses

when a function is provided, it will be called with the response and should return whether the response is valid. if it returns false, the response will be thrown as an HttpError

true