sttp.tapir.server.interceptor

Type members

Classlikes

case
class CustomInterceptors[F[_], O](createOptions: CustomInterceptors[F, O] => O, metricsInterceptor: Option[MetricsRequestInterceptor[F]], rejectInterceptor: Option[RejectInterceptor[F]], exceptionHandler: Option[ExceptionHandler], serverLog: Option[ServerLog[F]], additionalInterceptors: List[Interceptor[F]], unsupportedMediaTypeInterceptor: Option[UnsupportedMediaTypeInterceptor[F]], decodeFailureHandler: DecodeFailureHandler)

Allows customising the interceptors used by the server interpreter. Custom interceptors can be added via addInterceptor, sitting between two configurable, default interceptor groups.

Allows customising the interceptors used by the server interpreter. Custom interceptors can be added via addInterceptor, sitting between two configurable, default interceptor groups.

The order of the interceptors corresponds to the ordering of the parameters.

Moreover, built-in interceptors can be customised or disabled. Once done, use .options to obtain the server interpreter options to use.

Value Params
additionalInterceptors

Additional interceptors, e.g. handling decode failures, or providing alternate responses.

decodeFailureHandler

The decode failure handler, from which an interceptor will be created. Determines whether to respond when an input fails to decode.

exceptionHandler

Whether to respond to exceptions in the server logic, or propagate them to the server.

metricsInterceptor

Whether to collect metrics.

rejectInterceptor

How to respond when decoding fails for all interpreted endpoints.

serverLog

The server log using which an interceptor will be created, if any.

unsupportedMediaTypeInterceptor

Whether to return 415 (unsupported media type) if there's no body in the endpoint's outputs, which can satisfy the constraints from the Accept header.

case
class DecodeFailureContext(failingInput: EndpointInput[_], failure: Failure, endpoint: AnyEndpoint, request: ServerRequest)
case
class DecodeSuccessContext[F[_], U, I](serverEndpoint: ServerEndpoint[_, F] { type A; type U = U; type I = I; type E; type O; }, securityLogicResult: U, decodedInput: I, request: ServerRequest)
trait EndpointHandler[F[_], B]

Handles the result of decoding a request using an endpoint's inputs.

Handles the result of decoding a request using an endpoint's inputs.

trait EndpointInterceptor[F[_]] extends Interceptor[F]

Allows intercepting the handling of a request by an endpoint, when either the endpoint's inputs have been decoded successfully, or when decoding has failed. Ultimately, when all interceptors are run, the endpoint's server logic will be run (in case of a decode success), or None will be returned (in case of decode failure).

Allows intercepting the handling of a request by an endpoint, when either the endpoint's inputs have been decoded successfully, or when decoding has failed. Ultimately, when all interceptors are run, the endpoint's server logic will be run (in case of a decode success), or None will be returned (in case of decode failure).

Instead of calling the nested behavior, alternative responses can be returned using the responder.

Companion
object
Companion
class
sealed
trait Interceptor[F[_]]

Intercepts requests, and endpoint decode events. Using interceptors it's possible to:

Intercepts requests, and endpoint decode events. Using interceptors it's possible to:

  • customise the request that is passed downstream
  • short-circuit further processing and provide an alternate (or no) response
  • replace or modify the response that is sent back to the client

Interceptors can be called when the request is started to be processed (use RequestInterceptor in this case), or for each endpoint, with either input success of failure decoding events (see EndpointInterceptor).

To add an interceptors, modify the server options of the server interpreter.

Type Params
F

The effect type constructor.

trait RequestHandler[F[_], B]
Companion
object
Companion
class
trait RequestInterceptor[F[_]] extends Interceptor[F]

Allows intercepting the handling of request, before decoding using any of the endpoints is done. The request can be modified, before invoking further behavior, passed through requestHandler. Ultimately, when all interceptors are run, logic decoding subsequent endpoint inputs will be run.

Allows intercepting the handling of request, before decoding using any of the endpoints is done. The request can be modified, before invoking further behavior, passed through requestHandler. Ultimately, when all interceptors are run, logic decoding subsequent endpoint inputs will be run.

A request interceptor is called once for a request.

Instead of calling the nested behavior, alternative responses can be returned using the responder.

Moreover, when calling requestHandler, an EndpointInterceptor can be provided, which will be added to the list of endpoint interceptors to call. The order in which the endpoint interceptors will be called will correspond to their order in the interceptors list in the server options. An "empty" interceptor can be provided using EndpointInterceptor.noop.

Type Params
F

The effect type constructor.

sealed
trait RequestResult[+B]

The result of processing a request: either a response, or a list of endpoint decoding failures.

The result of processing a request: either a response, or a list of endpoint decoding failures.

Companion
object
Companion
class
trait Responder[F[_], B]
case
class SecurityFailureContext[F[_], A](serverEndpoint: ServerEndpoint[_, F] { type A = A; type U; type I; type E; type O; }, a: A, request: ServerRequest)
case
class ValuedEndpointOutput[T](output: EndpointOutput[T], value: T)