Skip to main content

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

PropertyTypeDescription
contentHttpMediaType[]One entry per supported content type. The adapter selects the matching entry based on the request's Content-Type header.
descriptionstring | undefinedHuman-readable description of the request body.
requiredboolean | undefinedWhether the body must be present.
maxContentSizenumber | undefinedMaximum allowed body size in bytes.
partialboolean | 'deep' | undefinedMakes all body fields optional. 'deep' applies recursively to nested types.
immediateFetchboolean | undefinedIf true, the adapter reads and buffers the body immediately before calling the handler.
allowPatchOperatorsboolean | undefinedAllows _$push / _$pull patch operator fields in the decoded body.
keepKeyFieldsboolean | undefinedKeeps key fields even when partial mode would otherwise strip them.
allowNullOptionalsboolean | undefinedAccepts null in place of absent optional fields.
ownerHttpOperationThe 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

HttpOperation · HttpMediaType