@podium/client
Version:
Client for fetching podium component fragments over HTTP.
36 lines (35 loc) • 1.48 kB
TypeScript
/**
* @typedef {object} PodiumHttpClientRequestOptions
* @property {'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH'} method
* @property {boolean} [json]
* @property {boolean} [rejectUnauthorized]
* @property {boolean} [follow]
* @property {number} [timeout]
* @property {object} [query]
* @property {import('http').IncomingHttpHeaders} [headers]
* @property {(info: { statusCode: number; headers: Record<string, string | string[]>; }) => void} [onInfo]
*/
export default class HTTP {
constructor(requestFn?: typeof undiciRequest);
requestFn: typeof undiciRequest;
/**
* @param {string} url
* @param {PodiumHttpClientRequestOptions} options
* @returns {Promise<Pick<import('undici').Dispatcher.ResponseData, 'statusCode' | 'headers' | 'body'>>}
*/
request(url: string, options: PodiumHttpClientRequestOptions): Promise<Pick<import("undici").Dispatcher.ResponseData, "statusCode" | "headers" | "body">>;
}
export type PodiumHttpClientRequestOptions = {
method: "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH";
json?: boolean;
rejectUnauthorized?: boolean;
follow?: boolean;
timeout?: number;
query?: object;
headers?: import("http").IncomingHttpHeaders;
onInfo?: (info: {
statusCode: number;
headers: Record<string, string | string[]>;
}) => void;
};
import { request as undiciRequest } from 'undici';