Routes

zio.http.Routes
See theRoutes companion object
final class Routes[-Env, +Err]

Represents a collection of routes, each of which is defined by a pattern and a handler. This data type can be thought of as modeling a routing table, which decides where to direct every endpoint in an API based on both method and path of the request.

When you are done building a collection of routes, you typically convert the routes into an zio.http.HttpApp value, which can be done with the toHttpApp method.

Routes may have handled or unhandled errors. A route of type Route[Env, Throwable], for example, has not handled its errors by converting them into responses. Such unfinished routes cannot yet be converted into zio.http.HttpApp values. First, you must handle errors with the handleError or handleErrorCause methods.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Routes[Env, Err]

Members list

Value members

Concrete methods

def ++[Env1 <: Env, Err1 >: Err](that: Routes[Env1, Err1]): Routes[Env1, Err1]

Returns the concatenation of these routes with the specified routes.

Returns the concatenation of these routes with the specified routes.

Attributes

def +:[Env1 <: Env, Err1 >: Err](route: Route[Env1, Err1]): Routes[Env1, Err1]

Prepends the specified route to this collection of routes.

Prepends the specified route to this collection of routes.

Attributes

def :+[Env1 <: Env, Err1 >: Err](route: Route[Env1, Err1]): Routes[Env1, Err1]

Appends the specified route to this collection of routes.

Appends the specified route to this collection of routes.

Attributes

def @@[Env1 <: Env](aspect: Middleware[Env1]): Routes[Env1, Err]
def asEnvType[Env2](implicit ev: Env2 <:< Env): Routes[Env2, Err]
def asErrorType[Err2](implicit ev: Err <:< Err2): Routes[Env, Err2]
def handleError(f: Err => Response)(implicit trace: Trace): Routes[Env, Nothing]

Handles all typed errors in the routes by converting them into responses.

Handles all typed errors in the routes by converting them into responses.

Attributes

def handleErrorCause(f: Cause[Err] => Response)(implicit trace: Trace): Routes[Env, Nothing]

Handles all typed errors, as well as all non-recoverable errors, by converting them into responses.

Handles all typed errors, as well as all non-recoverable errors, by converting them into responses.

Attributes

def provideEnvironment(env: ZEnvironment[Env]): Routes[Any, Err]

Returns new routes that have each been provided the specified environment, thus eliminating their requirement for any specific environment.

Returns new routes that have each been provided the specified environment, thus eliminating their requirement for any specific environment.

Attributes

def sandbox(implicit trace: Trace): Routes[Env, Nothing]

Returns new routes that automatically translate all failures into responses, using best-effort heuristics to determine the appropriate HTTP status code, and attaching error details using the HTTP header Warning.

Returns new routes that automatically translate all failures into responses, using best-effort heuristics to determine the appropriate HTTP status code, and attaching error details using the HTTP header Warning.

Attributes

def timeout(duration: Duration)(implicit trace: Trace): Routes[Env, Err]

Returns new routes that are all timed out by the specified maximum duration.

Returns new routes that are all timed out by the specified maximum duration.

Attributes

def toHttpApp(implicit ev: Err <:< Response): HttpApp[Env]

Converts the routes into an app, which can be done only when errors are handled and converted into responses.

Converts the routes into an app, which can be done only when errors are handled and converted into responses.

Attributes

def transform[Env1](f: Handler[Env, Response, Request, Response] => Handler[Env1, Response, Request, Response]): Routes[Env1, Err]

Returns new routes whose handlers are transformed by the specified function.

Returns new routes whose handlers are transformed by the specified function.

Attributes

Concrete fields

val routes: Chunk[Route[Env, Err]]