Import it from ky.
Options are the same as window.fetch, except for the KyOptions
tsinterface Options extends KyOptions, RequestOptions
Properties
| Name | Type | Default | Description |
|---|---|---|---|
method? | LiteralUnion<HttpMethod, string> | undefined | HTTP method used to make the request. | |
headers? | KyHeadersInit | undefined | HTTP headers used to make the request. | |
signal? | AbortSignal | null | undefined | An AbortSignal to abort the request. | |
json? | unknown | Shortcut for sending JSON. Use this instead of the body option. | |
parseJson? | ((text: string, context: {request: Request; response: Response}) => unknown) | undefined | JSON.parse() | User-defined JSON-parsing function. |
stringifyJson? | ((data: unknown) => string) | undefined | JSON.stringify() | User-defined JSON-stringifying function. |
searchParams? | SearchParamsOption | Search parameters to include in the request URL. Setting this will merge with any existing search parameters in the input URL. | |
baseUrl? | URL | string | undefined | A base URL to resolve the input against. When the input (after applying the prefix option) is only a relative URL, such as 'users', '/users', or '//my-site.com', it will be resolved against the baseUrl to determine the destination of the request. | |
prefix? | URL | string | undefined | A prefix to prepend to the input before making the request (and before it is resolved against the baseUrl). It can be any valid path or URL, either relative or absolute. A trailing slash / is optional and will be added automatically, if needed, when it is joined with input. Only takes effect when input is a string. | |
retry? | RetryOptions | number | undefined | Controls retry behavior. Each field is documented in the RetryOptions type. | |
timeout? | number | false | undefined | 10000 | Per-attempt timeout in milliseconds for getting a response, applied independently to each retry. Ky shortcut methods also use this value as a separate timeout for reading the response body. Cannot be greater than 2147483647. See also totalTimeout. |
totalTimeout? | number | false | undefined | false | Overall timeout in milliseconds for the entire operation, including retries and delays. Throws a TimeoutError if exceeded. Cannot be greater than 2147483647. |
maxResponseSize? (not released yet) | number | undefined | Infinity | Maximum response body size in bytes. Must be a non-negative safe integer or Infinity. Set to 0 to allow only empty bodies. |
hooks? | Hooks | undefined | Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially, unless otherwise noted. | |
throwHttpErrors? | boolean | ((status: number) => boolean) | undefined | true | Throw an HTTPError when, after following redirects, the response has a non-2xx status code. To also throw for redirects instead of following them, set the redirect option to 'manual'. |
onDownloadProgress? | ((progress: Progress, chunk: Uint8Array) => void) | undefined | Download progress event handler. | |
onUploadProgress? | ((progress: Progress, chunk: Uint8Array) => void) | undefined | Upload progress event handler. | |
fetch? | ((input: Request, init?: RequestInit) => Promise<Response>) | undefined | fetch | User-defined fetch function. Has to be fully compatible with the Fetch API standard. |
context? | Record<string, unknown> | undefined | {} | User-defined data passed to hooks. |
Was this page helpful?