Skip to content

TypeScript API / laikacms/json-api / JsonApiHttpTransport

Class: JsonApiHttpTransport ​

HTTP transport shared by the JSON:API proxy repositories: owns the base URL, auth headers, and the Effect HttpClient, and centralizes JSON:API response decoding (content-type validation, errors[] → typed LaikaError rehydration).

Constructors ​

Constructor ​

ts
new JsonApiHttpTransport(config): JsonApiHttpTransport;

Parameters ​

ParameterType
configJsonApiHttpTransportConfig

Returns ​

JsonApiHttpTransport

Methods ​

fetchJson() ​

ts
fetchJson(
   path, 
   init?, 
   opts?
): Effect<object & Record<string, unknown>, LaikaError<ErrorCode, number>>;

Execute a request and decode the JSON:API document: validates the content-type, surfaces non-JSON bodies (typically upstream stack traces) in the failure message, and turns errors[] into a fatal LaikaError.

Parameters ​

ParameterTypeDescription
pathstring-
initJsonApiRequestInit-
opts?{ rehydrateErrorCodes?: boolean; }-
opts.rehydrateErrorCodes?booleanRe-hydrate the upstream error's typed LaikaError subclass from its code field (falling back to InvalidData) so consumers can instanceof-check (e.g. NotFoundError).

Returns ​

Effect<object & Record<string, unknown>, LaikaError<ErrorCode, number>>


request() ​

ts
request(path, init?): Effect<HttpClientResponse, LaikaError<ErrorCode, number>>;

Execute a request and return the raw response. Transport failures are mapped through networkError; HTTP error statuses are NOT failures here — JSON:API error documents are decoded by fetchJson.

Parameters ​

ParameterType
pathstring
initJsonApiRequestInit

Returns ​

Effect<HttpClientResponse, LaikaError<ErrorCode, number>>

Released under the MIT License.