OpraMiddleware
NestJS middleware that creates an OPRA HttpContext for each incoming HTTP request and attaches it to the request object as req.opraContext. Downstream guards, interceptors, and handlers can read this context to access OPRA's parsed parameters, typed body, and response utilities.
import { OpraMiddleware } from '@opra/nestjs-http';
Implements: NestMiddleware
OpraHttpModule registers this middleware automatically on all routes — you do not need to apply it manually.
How it works
For each request, OpraMiddleware:
- Creates an
HttpRequestandHttpResponsewrapper around the raw Express/Fastify objects. - Calls
opraAdapter.createContext(request, response)to produce anHttpContext. - Sets
req.opraContext = context. - Calls
next()so the NestJS pipeline continues.
If context creation fails (e.g. the route is not an OPRA operation), req.opraContext remains unset and the request is handled by NestJS normally.
See also
OpraExceptionFilter— usesreq.opraContextto route error responsesHttpContext