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:
| Property | Type | Description |
|---|---|---|
request | HttpRequest | The raw incoming batch request. |
response | HttpResponse | The outgoing response that will carry the multipart result. |
headers | Record<string, any> | Decoded request headers from the batch request. |
cookies | Record<string, any> | Decoded cookies from the batch request. |
pathParams | Record<string, any> | Decoded path parameters from the batch request URL. |
queryParams | Record<string, any> | Decoded query parameters from the batch request URL. |
contexts | HttpContext[] | One HttpContext per sub-request in the batch. |
size | number | Number of sub-requests in the bundle (contexts.length). |
transaction | boolean | undefined | true 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.
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:
| Event | Payload | Emitted when |
|---|---|---|
'before-execute' | bundle: HttpBundle | Before processing the first sub-request. |
'after-execute' | bundle: HttpBundle | After all sub-requests complete. |
'error' | error: OpraException, bundle: HttpBundle | A fatal bundle-level error occurred. |
'finish' | bundle: HttpBundle | Bundle lifecycle complete. Always fires. |
These events are also emitted on the adapter with a bundle- prefix. See HttpAdapter.Events.
HttpBundle.Initiator
| Property | Type | Description |
|---|---|---|
__adapter | HttpAdapter | The HTTP adapter. |
request | HttpRequest | The incoming batch request. |
response | HttpResponse | The outgoing response. |
cookies | Record<string, any> | undefined | Pre-decoded cookies. |
headers | Record<string, any> | undefined | Pre-decoded headers. |
pathParams | Record<string, any> | undefined | Pre-decoded path parameters. |
queryParams | Record<string, any> | undefined | Pre-decoded query parameters. |