@mcsb/api / Exports / RawResponse
Class: RawResponse
A container around Response for HTTP responses from APIs that integrates Zod schema parsing.
See
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
Errorif 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
| Name | Type |
|---|---|
T | extends ZodType<any, ZodTypeDef, any> |
Parameters
| Name | Type | Description |
|---|---|---|
schema | T | The Zod schema to parse the body with. |
Returns
Promise<TypeOf<T>>
the parsed API response
Throws
Errorif the response is not JSON.Errorif the response JSON does not match the given schema.
See
Defined in
packages/api/src/BaseAPI.ts:48
text
▸ text(): string
Get the API response body as plain text.
Returns
string
Starboard