Skip to main content

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

PropertyTypeDescription
namestringOperation name (typically the method name).
method'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'SEARCH'HTTP method.
pathstring | undefinedURL path segment appended to the controller path.
mergePathboolean | undefinedIf true, path is appended without joining separator.
descriptionstring | undefinedHuman-readable description.
parametersHttpParameter[]Parameters declared on this operation.
responsesHttpOperationResponse[]Declared response shapes.
requestBodyHttpRequestBody | undefinedThe request body definition, if any.
typesDataTypeMapTypes scoped to this operation.
ownerHttpControllerThe controller that owns this operation.
compositionstring | undefinedComposition preset name (used by Entity operations).
compositionOptionsRecord<string, any> | undefinedOptions 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