Skip to main content

HttpHandler

HttpHandler processes incoming HTTP requests for an HttpAdapter. It runs request parsing, the interceptor chain, operation dispatch, and response serialization. Each HttpAdapter instance owns exactly one HttpHandler.

import { HttpHandler } from '@opra/http';

You do not instantiate HttpHandler directly — it is created by HttpAdapter and exposed via adapter.handler.


Methods

handleRequest

handleRequest(context: HttpContext): Promise<void>

Main entry point. Sets OPRA response headers, runs parseRequest, fires the 'request' event, executes the interceptor chain, calls the operation handler, and sends the response. On error, wraps the exception with wrapException and sends an error response.


parseRequest

parseRequest(context: HttpContext): Promise<void>

Decodes all declared parameters (cookies, headers, path, query) and validates the Content-Type against the operation's .RequestContent() declaration. Sets the default response status code from the first declared 2xx response.


sendResponse

sendResponse(context: HttpContext, responseValue?: any): Promise<void>

Serializes and sends the response. Validates and encodes the body against the declared HttpOperationResponse type. Handles OperationResult wrapping, content-type negotiation, and error fallback.


sendDocumentSchema

sendDocumentSchema(context: HttpContext): Promise<void>

Responds with the full ApiDocument serialized as JSON. Used by the GET {basePath}/$schema endpoint.


Interfaces

HttpHandler.ResponseArgs

Internal shape used by _determineResponseArgs to carry resolved response metadata.

PropertyTypeDescription
statusCodenumberHTTP status code to send.
contentTypestring | undefinedResolved Content-Type value.
operationResponseHttpOperationResponse | undefinedThe matched HttpOperationResponse declaration.
bodyanyThe response body after encoding.
projectionstring[] | '*' | undefinedField projection applied during encoding.