Skip to main content

DenchBuilder

Summary

A generic interface that defines the authentication, Fetch options, cancellation, error handling, and URL normalization APIs shared by all request builders.

Type Definition

interface DenchBuilder<T, R extends DenchBuilder<T, R>> {
config: DenchBaseConfig;
copy: () => R;
debug: () => R;
auth: (token: string, type?: DenchAuthType) => R;
credentials: (credentials: HTTPCredentials) => R;
mode: (mode: HTTPMode) => R;
cache: (cache: HTTPCache) => R;
redirect: (redirect: HTTPRedirect) => R;
referrerPolicy: (policy: HTTPReferrerPolicy) => R;
abort: (controller: AbortController) => R;
timeout: (ms: number) => R;
error: (callback: (error: unknown) => void) => R;
params: (params: DenchURLSearchParams) => R;
boundaryNormalize: () => R;
hardNormalize: () => R;
URLNormalize: (normalizeMode: DenchURLNormalizeMode) => R;
}

Generics

GenericDescription
TThe JSON response type of the request.
RThe concrete builder type returned by each chaining method. It must extend DenchBuilder<T, R>.

Properties

PropertyTypeRequiredDescription
configDenchBaseConfigYesThe current builder's URL and request configuration.
copy() => RYesReturns a builder containing a copy of the current configuration.
debug() => RYesPrints the builder configuration at the current chain position and returns the same builder type.
auth(token: string, type?: DenchAuthType) => RYesSets the Authorization header.
credentials(credentials: HTTPCredentials) => RYesSets the Fetch credentials policy.
mode(mode: HTTPMode) => RYesSets the Fetch request mode.
cache(cache: HTTPCache) => RYesSets the Fetch cache policy.
redirect(redirect: HTTPRedirect) => RYesSets the redirect handling policy.
referrerPolicy(policy: HTTPReferrerPolicy) => RYesSets the referrer policy.
abort(controller: AbortController) => RYesConnects an AbortController to the request.
timeout(ms: number) => RYesSets the request timeout in milliseconds.
error(callback: (error: unknown) => void) => RYesSets the request error callback.
params(params: DenchURLSearchParams) => RYesAccepts URL query parameter input. In the current 0.1.0-beta.7 implementation, the value is not applied to the URL.
boundaryNormalize() => RYesSelects boundary URL normalization.
hardNormalize() => RYesSelects strict URL normalization.
URLNormalize(normalizeMode: DenchURLNormalizeMode) => RYesSets the URL normalization mode directly.

Used By

  • Extended by DenchCreateBuilder<T> as DenchBuilder<T, DenchCreateBuilder<T>>.
  • Extended by DenchGetBuilder<T> as DenchBuilder<T, DenchGetBuilder<T>>.
  • Defines the common chaining APIs for POST, PUT, GET, and DELETE request builders.
import type { DenchBuilder } from 'dench-fetch';