Skip to main content
Module

x/bcdeno_api/deps.ts>Options

🎲 Use BCDice-API from Deno easily
Latest
interface Options
implements Omit<RequestInit, "headers">
import { type Options } from "https://deno.land/x/bcdeno_api@v1.1.1/deps.ts";

Options are the same as window.fetch, with some exceptions.

Properties

optional
method: LiteralUnion<HttpMethod, string>

HTTP method used to make the request.

Internally, the standard methods (`GET`, `POST`, `PUT`, `PATCH`, `HEAD` and `DELETE`) are uppercased in order to avoid server errors due to case sensitivity.
optional
headers: KyHeadersInit

HTTP headers used to make the request.

You can pass a `Headers` instance or a plain object.

You can remove a header with `.extend()` by passing the header with an `undefined` value.
optional
json: unknown

Shortcut for sending JSON. Use this instead of the body option.

Accepts any plain object or value, which will be `JSON.stringify()`'d and sent in the body with the correct header set.
optional
parseJson: (text: string) => unknown

User-defined JSON-parsing function.

Use-cases:
1. Parse JSON via the [`bourne` package](https://github.com/hapijs/bourne) to protect from prototype pollution.
2. Parse JSON with [`reviver` option of `JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
optional
searchParams: SearchParamsOption

Search parameters to include in the request URL. Setting this will override all existing search parameters in the input URL.

Accepts any value supported by [`URLSearchParams()`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams).
optional
prefixUrl: URL | string

A prefix to prepend to the input URL when making the request. It can be any valid 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. The input argument cannot start with a slash / when using this option.

Useful when used with [`ky.extend()`](#kyextenddefaultoptions) to create niche-specific Ky-instances.

Notes:
 - After `prefixUrl` and `input` are joined, the result is resolved against the [base URL](https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI) of the page (if any).
 - Leading slashes in `input` are disallowed when using this option to enforce consistency and avoid confusion about how the `input` URL is handled, given that `input` will not follow the normal URL resolution rules when `prefixUrl` is being used, which changes the meaning of a leading slash.
optional
retry: RetryOptions | number

An object representing limit, methods, statusCodes and maxRetryAfter fields for maximum retry count, allowed methods, allowed status codes and maximum Retry-After time.

If `retry` is a number, it will be used as `limit` and other defaults will remain in place.

If `maxRetryAfter` is set to `undefined`, it will use `options.timeout`. If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will cancel the request.

Delays between retries is calculated with the function `0.3(2 ** (retry - 1)) * 1000`, where `retry` is the attempt number (starts from 1).

Retries are not triggered following a timeout.
optional
timeout: number | false

Timeout in milliseconds for getting a response, including any retries. Can not be greater than 2147483647. If set to false, there will be no timeout.

optional
hooks: Hooks

Hooks allow modifications during the request lifecycle. Hook functions may be async and are run serially.

optional
throwHttpErrors: boolean

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'.

Setting this to `false` may be useful if you are checking for resource availability and are expecting error responses.

Note: If `false`, error responses are considered successful and the request will not be retried.
optional
onDownloadProgress: (progress: DownloadProgress, chunk: Uint8Array) => void

Download progress event handler.

optional
fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>

User-defined fetch function. Has to be fully compatible with the Fetch API standard.

Use-cases:
1. Use custom `fetch` implementations like [`isomorphic-unfetch`](https://www.npmjs.com/package/isomorphic-unfetch).
2. Use the `fetch` wrapper function provided by some frameworks that use server-side rendering (SSR).