Skip to main content

HttpAdapter

HttpAdapter is the abstract base class for all HTTP platform adapters. It manages the interceptor chain, base path, scope, and the HttpHandler that processes every incoming request.

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

Extends: PlatformAdapter

You do not instantiate HttpAdapter directly. Extend ExpressAdapter or implement your own platform adapter subclass.


Properties

PropertyTypeDescription
handlerHttpHandlerThe HttpHandler instance that processes requests.
transform'http'Always 'http'. Identifies the transport type.
basePathstringURL prefix prepended to all OPRA routes. Defaults to '/'.
scopestring | undefinedValidation scope applied to every request and response.
interceptors(InterceptorFunction | IHttpInterceptor)[]Mutable interceptor chain executed on every request.
apiHttpApiThe HTTP API definition from the document. Shorthand for document.getHttpApi().

Interfaces

HttpAdapter.Options

OptionTypeDefaultDescription
basePathstring'/'URL prefix for all OPRA routes.
scopestring | '*'Validation scope applied to every request and response. '*' disables scope filtering.
interceptors(InterceptorFunction | IHttpInterceptor)[][]Interceptor chain executed on every request.

HttpAdapter.IHttpInterceptor

type IHttpInterceptor = {
intercept(context: HttpContext, next: NextCallback): Promise<void>;
};

Class-based interceptor interface. Implement intercept to wrap request processing.


HttpAdapter.InterceptorFunction

type InterceptorFunction = (context: HttpContext, next: NextCallback) => Promise<void>;

Function-based interceptor. Equivalent to IHttpInterceptor['intercept'].


HttpAdapter.NextCallback

type NextCallback = () => Promise<void>;

Async function passed to interceptors. Call await next() to continue to the next interceptor or the operation handler.


HttpAdapter.Events

EventPayloadEmitted when
'createContext'HttpContextA new HttpContext has been created, before interceptors run.
'request'HttpContextThe request enters the interceptor chain.
'finish'HttpContextThe response has been sent and the request lifecycle is complete.
'error'Error, HttpContextAn unhandled error occurred during request processing.