Skip to content

routeWithRaise

@JvmName(name = "routeOrRaise1")
inline fun <In : Any, Out : Any, F1 : Any, Failure : FailureSpec.Or<FailureSpec.Never, FailureSpec.ByCode<F1>>, Params : Parameters> Route.routeWithRaise(endpoint: Endpoint<In, Out, Failure, Params>, crossinline block: context(Raise<F1>) suspend TypedResponseScope<In, Out, FailureSpec.Or<FailureSpec.Never, FailureSpec.ByCode<F1>>, Params>.() -> Unit)

Declares a Ktor handler matching a Spine endpoint.

The handler has the ability to Raise, including using any method from the Arrow DSL.

Example

routing {
    route(Api.Users.logIn) {
        ensure(body.password.size > 12) { PasswordTooShort }

        val (user, token) = withError({ IncorrectCredentials }) {
            call.response.cookies.append("token", token)
        }

        respond(user)
    }
}

For the full list of available methods, see TypedResponseScope.