handle(request:requestBody:metadata:forOperation:using:deserializer:serializer:)
Performs the operation.
This declaration is gated by at least one @_spi attribute.
func handle<OperationInput, OperationOutput>(request: HTTPRequest, requestBody: HTTPBody?, metadata: ServerRequestMetadata, forOperation operationID: String, using handlerMethod: @escaping (APIHandler) -> ((OperationInput) async throws -> OperationOutput), deserializer: @escaping (HTTPRequest, HTTPBody?, ServerRequestMetadata) async throws -> OperationInput, serializer: @escaping (OperationOutput, HTTPRequest) throws -> (HTTPResponse, HTTPBody?)) async throws -> (HTTPResponse, HTTPBody?) where OperationInput : Sendable, OperationOutput : Sendable Parameters
- request
The HTTP request.
- requestBody
The HTTP request body.
- metadata
The HTTP request metadata.
- operationID
The OpenAPI operation identifier.
- handlerMethod
The user handler method.
- deserializer
A closure that creates an Input value from the provided HTTP request.
- serializer
A closure that creates an HTTP response from the provided Output value.
Returns
The HTTP response and its body produced by the serializer.
Throws
An error if any part of the operation process fails.
Should only be called by generated code, not directly.
An operation consists of three steps (middlewares happen before 1 and after 3):
Convert HTTP request into Input.
Invoke the user handler to perform the user logic.
Convert Output into an HTTP response.
It wraps any thrown errors and attaching appropriate context.