Skip to main content

fetchJSON()

function fetchJSON<V>(
url,
method,
options): Promise<[V | null, Headers]>

Perform an HTTP fetch where input and output data is Json.

Type Parameters

Type ParameterDescription
V extends JsonType response is assumed to have.

Parameters

ParameterTypeDefault valueDescription
urlstringundefinedURL from which to fetch.
method"POST" | "GET" | "PUT" | "PATCH" | "HEAD" | "DELETE""GET"HTTP method of request.
options{ body: Json; headers: {}; timeout: number; }...Optional parameters.
options.body?JsonundefinedData to convert to JSON and send in request body.
options.headers?{}undefinedAdditional headers to add to request.
options.timeout?numberundefinedTimeout for request, in milliseconds. Defaults to 1000ms.

Returns

Promise<[V | null, Headers]>

Response parsed as JSON, and headers.