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
| Property | Type | Description |
|---|---|---|
handler | HttpHandler | The HttpHandler instance that processes requests. |
transform | 'http' | Always 'http'. Identifies the transport type. |
basePath | string | URL prefix prepended to all OPRA routes. Defaults to '/'. |
scope | string | undefined | Validation scope applied to every request and response. |
interceptors | (InterceptorFunction | IHttpInterceptor)[] | Mutable interceptor chain executed on every request. |
api | HttpApi | The HTTP API definition from the document. Shorthand for document.getHttpApi(). |
Interfaces
HttpAdapter.Options
| Option | Type | Default | Description |
|---|---|---|---|
basePath | string | '/' | URL prefix for all OPRA routes. |
scope | string | '*' | — | 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
| Event | Payload | Emitted when |
|---|---|---|
'createContext' | HttpContext | A new HttpContext has been created, before interceptors run. |
'request' | HttpContext | The request enters the interceptor chain. |
'finish' | HttpContext | The response has been sent and the request lifecycle is complete. |
'error' | Error, HttpContext | An unhandled error occurred during request processing. |