Skip to content

@mcsb/api / Exports / RawResponse

Class: RawResponse ​

A container around Response for HTTP responses from APIs that integrates Zod schema parsing.

See

https://zod.dev/

Table of contents ​

Properties ​

Methods ​

Properties ​

response ​

• Readonly response: Response

The original Response from the fetch() call. This can be used to read headers and status codes from the response, however it should not be used to read the body. Instead, use json or text.

Defined in ​

packages/api/src/BaseAPI.ts:18

Methods ​

json ​

▸ json(): any

Get the API response body and attempt to parse it as JSON.

Returns ​

any

Throws

  • Error if the API response is not valid JSON.

Defined in ​

packages/api/src/BaseAPI.ts:57


parse ​

▸ parse<T>(schema): Promise<TypeOf<T>>

Parse this responses JSON body using a Zod schema.

Type parameters ​

NameType
Textends ZodType<any, ZodTypeDef, any>

Parameters ​

NameTypeDescription
schemaTThe Zod schema to parse the body with.

Returns ​

Promise<TypeOf<T>>

the parsed API response

Throws

  • Error if the response is not JSON.
  • Error if the response JSON does not match the given schema.

See

https://zod.dev/

Defined in ​

packages/api/src/BaseAPI.ts:48


text ​

▸ text(): string

Get the API response body as plain text.

Returns ​

string

Defined in ​

packages/api/src/BaseAPI.ts:64

Released under the MIT License.