Skip to main content

DenchInterface

Summary

The API client type returned by dench(baseURL). It provides the base URL and request builder factory functions for each HTTP method.

Type Definition

interface DenchInterface {
baseURL: DenchHTTPURL;
get: <T>(api?: string) => DenchGetBuilder<T>;
post: <T>(api?: string, data?: unknown) => DenchCreateBuilder<T>;
put: <T>(api?: string, data?: unknown) => DenchCreateBuilder<T>;
delete: <T>(api?: string) => DenchGetBuilder<T>;
}

DenchInterface itself has no generics. The generic T on each HTTP method represents the JSON response type returned by toJson() for that request.

Properties

PropertyTypeRequiredDescription
baseURLDenchHTTPURLYesThe base URL used by the client.
get<T>(api?: string) => DenchGetBuilder<T>YesCreates a GET request builder.
post<T>(api?: string, data?: unknown) => DenchCreateBuilder<T>YesCreates a POST request builder.
put<T>(api?: string, data?: unknown) => DenchCreateBuilder<T>YesCreates a PUT request builder.
delete<T>(api?: string) => DenchGetBuilder<T>YesCreates a DELETE request builder.

Used By

  • Return type of the dench(baseURL) function.
  • Defines the get(), post(), put(), and delete() request builder factory APIs.
import { dench } from 'dench-fetch';
import type { DenchInterface } from 'dench-fetch';

const api: DenchInterface = dench('https://api.example.com');