Skip to content

TypedResponseScope

interface TypedResponseScope<out In : Any, out Out : Any, out Failure : FailureSpec, out Params : Parameters>

Properties

body

abstract val body: In

call

abstract val call: ApplicationCall

endpoint

abstract val endpoint: Endpoint<out In, out Out, out Failure, out Params>

parameters

abstract val parameters: Params

Functions

fail

@JvmName(name = "fail1")
inline suspend fun <F : Any> TypedResponseScope<*, *, FailureSpec.Or<*, FailureSpec.ByCode<F>>, *>.fail(failure: F): Nothing
@JvmName(name = "fail2")
inline suspend fun <F : Any> TypedResponseScope<*, *, FailureSpec.Or<FailureSpec.Or<*, FailureSpec.ByCode<F>>, Nothing>, *>.fail(failure: F): Nothing
@JvmName(name = "fail3")
inline suspend fun <F : Any> TypedResponseScope<*, *, FailureSpec.Or<FailureSpec.Or<FailureSpec.Or<*, FailureSpec.ByCode<F>>, Nothing>, Nothing>, *>.fail(failure: F): Nothing

idOf

open fun idOf(resource: DynamicResource<*>): String

Extracts the identifier for a DynamicResource as it was provided by the client.

For example, if we declare the following API:

object Api : RootResource("api") {
    object Users : StaticResource<Api>("users", Api) {
        object User : DynamicResource<Users>("user", Users) {
            val get by get()
        }
    }
}

and the client calls the endpoint GET /api/users/123, then we can declare our route as:

route(Api.Users.User) {
    val id = idOf(Api.Users.User) // "123", because this is what the client passed for this path parameter
}

respond

inline suspend fun <Out : Any> TypedResponseScope<*, Out, *, *>.respond(
    body: Out, 
    code: HttpStatusCode = if (body == Unit) HttpStatusCode.NoContent else HttpStatusCode.OK
)
suspend fun TypedResponseScope<*, Unit, *, *>.respond(code: HttpStatusCode = HttpStatusCode.NoContent)