ApiHandlerOptions
Options of apiHandler.
Options of apiHandler.
Import#
ts
import type { ApiHandlerOptions } from "@shadow-js/dusk/server";
Signature#
ts
interface ApiHandlerOptions<
B extends StandardSchemaV1 | undefined,
Q extends StandardSchemaV1 | undefined,
> {
/** Schema of the JSON body. A missing or malformed body gives 400/415. */
readonly body?: B;
/** Schema of the query string (an object of strings; repeated keys become arrays). */
readonly query?: Q;
/** Middleware that wraps this handler only. */
readonly middleware?: readonly Middleware[];
/**
* Guards that run before the body and the query are read or validated (see `serverFn`'s `guard`): a refused
* request gets its status and the handler does not run.
*/
readonly guard?: Guard | readonly Guard[];
/**
* Largest JSON body this handler reads, in bytes; larger gives 413 and the read stops at the bound. Default: the
* app's `limits.maxBodyBytes`. Set it on a handler whose body is small when the app allows large bodies elsewhere
* (uploads), so the handler does not buffer up to that limit.
*/
readonly maxBodyBytes?: number;
/**
* The message of the 413 answer when the handler's body is larger than its limit (`maxBodyBytes`, or the app's), whether
* the schema read it or the handler read it with `readJsonLimited` / `readFormLimited`. The answer is a 413 with the
* API error shape, so the app needs no mapping of its own. Default: `Payload Too Large`.
*/
readonly bodyTooLargeMessage?: string;
}
Members#
| Name | Type | Description |
|---|---|---|
B |
B extends StandardSchemaV1 | undefined |
|
Q |
Q extends StandardSchemaV1 | undefined |
|
body? |
readonly body?: B |
Schema of the JSON body. A missing or malformed body gives 400/415. |
query? |
readonly query?: Q |
Schema of the query string (an object of strings; repeated keys become arrays). |
middleware? |
readonly middleware?: readonly Middleware[] |
Middleware that wraps this handler only. |
guard? |
readonly guard?: Guard | readonly Guard[] |
Guards that run before the body and the query are read or validated (see serverFn's guard): a refused request gets its status and the handler does not run. |
maxBodyBytes? |
readonly maxBodyBytes?: number |
Largest JSON body this handler reads, in bytes; larger gives 413 and the read stops at the bound. Default: the app's limits.maxBodyBytes. Set it on a handler whose body is small when the app allows large bodies elsewhere (uploads), so the handler does not buffer up to that limit. |
bodyTooLargeMessage? |
readonly bodyTooLargeMessage?: string |
The message of the 413 answer when the handler's body is larger than its limit (maxBodyBytes, or the app's), whether the schema read it or the handler read it with readJsonLimited / readFormLimited. The answer is a 413 with the API error shape, so the app needs no mapping of its own. Default: Payload Too Large. |