Skip to main content

HttpBundle

HttpBundle is the execution bundle for HTTP multipart/mixed batch requests. When the adapter receives a POST /$bundle request with Content-Type: multipart/mixed, it creates an HttpBundle, processes each part as an independent HTTP sub-request, and returns a single multipart/mixed response whose parts correspond to the individual sub-responses.

Package: @opra/http
Extends: ExecutionBundle


Properties

Inherits all properties from ExecutionBundle, plus:

PropertyTypeDescription
requestHttpRequestThe raw incoming batch request.
responseHttpResponseThe outgoing response that will carry the multipart result.
headersRecord<string, any>Decoded request headers from the batch request.
cookiesRecord<string, any>Decoded cookies from the batch request.
pathParamsRecord<string, any>Decoded path parameters from the batch request URL.
queryParamsRecord<string, any>Decoded query parameters from the batch request URL.
contextsHttpContext[]One HttpContext per sub-request in the batch.
sizenumberNumber of sub-requests in the bundle (contexts.length).
transactionboolean | undefinedtrue when the ?transaction=true query parameter is present. Signals data service adapters (MongoDB, SQB) to wrap the entire batch in a single database transaction.

Transaction support

When transaction is true, data service adapters that support it (MongoDB, SQB) start a database session/transaction when the first operation in the bundle reads or writes the database, and commit or roll back the transaction when the bundle finishes:

POST /api/$bundle?transaction=true HTTP/1.1
Content-Type: multipart/mixed; boundary=---b

-----b
Content-Type: application/http
X-Request-Id: 1

POST /api/orders HTTP/1.1
...

-----b
Content-Type: application/http
X-Request-Id: 2

PATCH /api/inventory/item-42 HTTP/1.1
...

If any sub-request in the batch fails, the entire transaction is rolled back. On success, the transaction is committed after all sub-requests complete.

info

The transaction flag is automatically read from the ?transaction=true query parameter by HttpBundle. Your operation handlers do not need to handle it explicitly — the data service layer detects bundle.transaction and manages the session lifecycle automatically.


Events

HttpBundle emits the same events as ExecutionBundle:

EventPayloadEmitted when
'before-execute'bundle: HttpBundleBefore processing the first sub-request.
'after-execute'bundle: HttpBundleAfter all sub-requests complete.
'error'error: OpraException, bundle: HttpBundleA fatal bundle-level error occurred.
'finish'bundle: HttpBundleBundle lifecycle complete. Always fires.

These events are also emitted on the adapter with a bundle- prefix. See HttpAdapter.Events.


HttpBundle.Initiator

PropertyTypeDescription
__adapterHttpAdapterThe HTTP adapter.
requestHttpRequestThe incoming batch request.
responseHttpResponseThe outgoing response.
cookiesRecord<string, any> | undefinedPre-decoded cookies.
headersRecord<string, any> | undefinedPre-decoded headers.
pathParamsRecord<string, any> | undefinedPre-decoded path parameters.
queryParamsRecord<string, any> | undefinedPre-decoded query parameters.

Batch Requests · ExecutionBundle · HttpAdapter