HttpRequestBody
Package: @opra/common
HttpRequestBody represents the request body declaration on an HttpOperation. It holds one or more HttpMediaType entries (one per supported content type), size limits, and decoding options that control how the adapter reads and validates the incoming body.
Inheritance
DocumentElement
└── HttpRequestBody
Properties
| Property | Type | Description |
|---|---|---|
content | HttpMediaType[] | One entry per supported content type. The adapter selects the matching entry based on the request's Content-Type header. |
description | string | undefined | Human-readable description of the request body. |
required | boolean | undefined | Whether the body must be present. |
maxContentSize | number | undefined | Maximum allowed body size in bytes. |
partial | boolean | 'deep' | undefined | Makes all body fields optional. 'deep' applies recursively to nested types. |
immediateFetch | boolean | undefined | If true, the adapter reads and buffers the body immediately before calling the handler. |
allowPatchOperators | boolean | undefined | Allows _$push / _$pull patch operator fields in the decoded body. |
keepKeyFields | boolean | undefined | Keeps key fields even when partial mode would otherwise strip them. |
allowNullOptionals | boolean | undefined | Accepts null in place of absent optional fields. |
owner | HttpOperation | The operation this body belongs to. |
Accessing the request body at runtime
HttpRequestBody is a schema-level descriptor. At request time, read the body through HttpContext:
async create(ctx: HttpContext) {
const body = await ctx.getBody<Customer>();
}
To inspect the declaration programmatically:
const op = document.httpApi.findOperation('/customers', 'create');
const rb = op.requestBody;
if (rb) {
console.log(rb.required); // true | false | undefined
console.log(rb.maxContentSize); // number | undefined
for (const ct of rb.content) {
console.log(ct.contentType, ct.type?.name);
}
}
toJSON(options?)
Returns an OpraSchema.HttpRequestBody plain object for schema export.
toJSON(options?: ApiDocument.ExportOptions): OpraSchema.HttpRequestBody