HttpApi
Package: @opra/common
HttpApi is the runtime class that represents the HTTP transport layer of an OPRA document. It holds the controller registry, the base URL, and provides lookup methods for controllers and operations. You obtain it from an ApiDocument via document.httpApi or document.getHttpApi().
Inheritance
DocumentElement
└── ApiBase
└── HttpApi
Properties
Properties inherited from ApiBase:
| Property | Type | Description |
|---|---|---|
transport | 'http' | Always 'http'. |
name | string | API name (e.g. 'CustomerApi'). |
description | string | undefined | Human-readable description. |
owner | ApiDocument | The owning document. |
Properties on HttpApi:
| Property | Type | Description |
|---|---|---|
url | string | undefined | Base URL prefix for all routes (e.g. '/api'). |
controllers | ResponsiveMap<HttpController> | Registry of top-level controllers, keyed by name. |
Methods
findController(arg)
Finds a controller by its TypeScript class constructor or by its path string. Returns undefined if not found. Searches recursively through nested controllers.
const ctrl = httpApi.findController('/customers');
const ctrl = httpApi.findController(CustomersController);
findController(controller: Type): HttpController | undefined
findController(resourcePath: string): HttpController | undefined
findOperation(arg, operationName)
Finds an operation on a controller located by class or path.
const op = httpApi.findOperation('/customers', 'get');
const op = httpApi.findOperation(CustomersController, 'create');
findOperation(controller: Type, operationName: string): HttpOperation | undefined
findOperation(resourcePath: string, operationName: string): HttpOperation | undefined
toJSON(options?)
Returns an OpraSchema.HttpApi plain object for schema export.
toJSON(options?: ApiDocument.ExportOptions): OpraSchema.HttpApi
Obtaining an HttpApi instance
import { HttpApi } from '@opra/common';
const httpApi = document.httpApi; // throws if not an HttpApi document
const httpApi = document.getHttpApi(); // same, explicit getter
if (httpApi instanceof HttpApi) {
console.log(httpApi.transport); // 'http'
console.log(httpApi.url); // '/api'
for (const ctrl of httpApi.controllers.values()) {
console.log(ctrl.name);
}
}