HandlerAspect

zio.http.HandlerAspect
See theHandlerAspect companion object
final case class HandlerAspect[-Env, +CtxOut](protocol: ProtocolStack[Env, Request, (Request, CtxOut), Response, Response]) extends Middleware[Env]

A zio.http.HandlerAspect is a kind of zio.http.ProtocolStack that is specialized to transform a handler's incoming requests and outgoing responses. Each layer in the stack corresponds to a separate transformation.

Layers may incorporate layer-specific information into a generic type parameter, referred to as middleware context, which composes using tupling.

Layers may also be stateful at the level of each transformation application. So, for example, a layer that is timing request durations may capture the start time of the request in the incoming interceptor, and pass this state to the outgoing interceptor, which can then compute the duration.

zio.http.HandlerAspect is more than just a wrapper around zio.http.ProtocolStack, as its concatenation operator has been specialized to entuple contexts, so that each layer may only add context to the contextual output.

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Middleware[Env]
class Object
trait Matchable
class Any
Show all
Self type
HandlerAspect[Env, CtxOut]

Members list

Value members

Concrete methods

def ++[Env1 <: Env, CtxOut2](that: HandlerAspect[Env1, CtxOut2])(implicit zippable: Zippable[CtxOut, CtxOut2]): HandlerAspect[Env1, Out]

Combines this middleware with the specified middleware sequentially, such that this middleware will be applied first on incoming requests, and last on outgoing responses, and the specified middleware will be applied last on incoming requests, and first on outgoing responses. Context from both middleware will be combined using tuples.

Combines this middleware with the specified middleware sequentially, such that this middleware will be applied first on incoming requests, and last on outgoing responses, and the specified middleware will be applied last on incoming requests, and first on outgoing responses. Context from both middleware will be combined using tuples.

Attributes

def apply[Env1 <: Env, Err](routes: Routes[Env1, Err]): Routes[Env1, Err]

Applies middleware to the specified handler, which may ignore the context produced by this middleware.

Applies middleware to the specified handler, which may ignore the context produced by this middleware.

Attributes

def applyHandler[Env1 <: Env](handler: RequestHandler[Env1, Response]): RequestHandler[Env1, Response]
def applyHandlerContext[Env1 <: Env](handler: Handler[Env1, Response, (CtxOut, Request), Response]): Handler[Env1, Response, Request, Response]

Applies middleware to the specified handler, which must process the context produced by this middleware.

Applies middleware to the specified handler, which must process the context produced by this middleware.

Attributes

def as[CtxOut2](ctxOut2: => CtxOut2): HandlerAspect[Env, CtxOut2]

Returns new middleware that transforms the context of the middleware to the specified constant.

Returns new middleware that transforms the context of the middleware to the specified constant.

Attributes

def map[CtxOut2](f: CtxOut => CtxOut2): HandlerAspect[Env, CtxOut2]

Returns new middleware that transforms the context of the middleware using the specified function.

Returns new middleware that transforms the context of the middleware using the specified function.

Attributes

def provideEnvironment(env: ZEnvironment[Env]): HandlerAspect[Any, CtxOut]

Returns new middleware that fully provides the specified environment to this middleware, resulting in middleware that has no contextual dependencies.

Returns new middleware that fully provides the specified environment to this middleware, resulting in middleware that has no contextual dependencies.

Attributes

def unit: HandlerAspect[Env, Unit]

Returns new middleware that produces the unit value as its context.

Returns new middleware that produces the unit value as its context.

Attributes

def when(condition: Request => Boolean): HandlerAspect[Env, Unit]

Conditionally applies this middleware to the specified handler, based on the result of the predicate applied to the incoming request.

Conditionally applies this middleware to the specified handler, based on the result of the predicate applied to the incoming request.

Attributes

def whenHeader(condition: Headers => Boolean): HandlerAspect[Env, Unit]

Conditionally applies this middleware to the specified handler, based on the result of the predicate applied to the incoming request's headers.

Conditionally applies this middleware to the specified handler, based on the result of the predicate applied to the incoming request's headers.

Attributes

def whenZIO[Env1 <: Env](condition: Request => ZIO[Env1, Response, Boolean]): HandlerAspect[Env1, Unit]

Conditionally applies this middleware to the specified handler, based on the result of the effectful predicate applied to the incoming request.

Conditionally applies this middleware to the specified handler, based on the result of the effectful predicate applied to the incoming request.

Attributes

Inherited methods

def ++[UpperEnv1 <: Env](that: Middleware[UpperEnv1]): Middleware[UpperEnv1]

Attributes

Inherited from:
Middleware
def @@[UpperEnv1 <: Env](that: Middleware[UpperEnv1]): Middleware[UpperEnv1]

Attributes

Inherited from:
Middleware
def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product