HttpOperation
Package: @opra/common
HttpOperation is the runtime class that represents a single HTTP endpoint on a controller. It holds the HTTP method, path, declared parameters, request body, and response definitions.
The @HttpOperation() decorator and its shorthand variants are documented in the HTTP API schema section. This page covers the runtime class instance.
Inheritance
DocumentElement
└── HttpOperation
Properties
| Property | Type | Description |
|---|---|---|
name | string | Operation name (typically the method name). |
method | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'SEARCH' | HTTP method. |
path | string | undefined | URL path segment appended to the controller path. |
mergePath | boolean | undefined | If true, path is appended without joining separator. |
description | string | undefined | Human-readable description. |
parameters | HttpParameter[] | Parameters declared on this operation. |
responses | HttpOperationResponse[] | Declared response shapes. |
requestBody | HttpRequestBody | undefined | The request body definition, if any. |
types | DataTypeMap | Types scoped to this operation. |
owner | HttpController | The controller that owns this operation. |
composition | string | undefined | Composition preset name (used by Entity operations). |
compositionOptions | Record<string, any> | undefined | Options passed to the composition preset. |
Methods
findParameter(name, location?)
Finds a parameter declared on this operation by name and optional location. Name matching is case-insensitive; RegExp patterns are supported.
op.findParameter('id', 'path');
op.findParameter('x-request-id', 'header');
findParameter(
paramName: string,
location?: 'query' | 'path' | 'header' | 'cookie'
): HttpParameter | undefined
getFullUrl()
Returns the fully resolved URL for this operation (controller URL + operation path).
op.getFullUrl(); // e.g. '/api/customers/:customerId'
getFullUrl(): string
toJSON(options?)
Returns an OpraSchema.HttpOperation plain object for schema export.
toJSON(options?: ApiDocument.ExportOptions): OpraSchema.HttpOperation
Obtaining an HttpOperation instance
import { HttpOperation } from '@opra/common';
const op = document.httpApi.findOperation('/customers', 'create');
if (op instanceof HttpOperation) {
console.log(op.name); // 'create'
console.log(op.method); // 'POST'
console.log(op.getFullUrl()); // '/api/customers'
console.log(op.requestBody); // HttpRequestBody | undefined
console.log(op.responses); // HttpOperationResponse[]
}
→ HttpController · HttpParameter · HttpRequestBody · HttpOperationResponse