Skip to main content

CotomyApiResponse

Wrapper for a Fetch Response with lazy parsing helpers.

Constructor

  • new CotomyApiResponse(response?: Response | null) Wraps a Response (or an empty response).

Properties

PropertyTypeDescription
availablebooleantrue if a response object exists.
emptybooleantrue if there is no response or the status is 0.
okbooleanMirrors Response.ok.
statusnumberHTTP status code.
statusTextstringHTTP status text.
headersHeadersResponse headers.

Methods

MethodDescription
textAsync()Reads the response body as text (cached).
objectAsync(defaultValue?)Parses JSON into an object, returning defaultValue if empty.
arrayAsync(defaultValue?)Parses JSON into an array, returning defaultValue if not an array.