Package-level declarations

Types

Link copied to clipboard
data class AndRouteSelector(val first: RouteSelector, val second: RouteSelector) : RouteSelector

Evaluates a route as a result of the AND operation using two other selectors.

Link copied to clipboard
data class ConstantParameterRouteSelector(val name: String, val value: String) : RouteSelector

Evaluates a route against a constant query parameter value.

Link copied to clipboard
data class HostRouteSelector(val hostList: List<String>, val hostPatterns: List<Regex>, val portsList: List<Int>) : RouteSelector

Evaluates a route against a request's host and port.

Link copied to clipboard
data class HttpAcceptRouteSelector(val contentType: ContentType) : RouteSelector

Evaluates a route against a Content-Type in the HttpHeaders.Accept request header.

Link copied to clipboard
data class HttpHeaderRouteSelector(val name: String, val value: String) : RouteSelector

Evaluates a route against a header in the request.

Link copied to clipboard

Evaluates a route against an HttpMethod.

Link copied to clipboard

Evaluates a route against a Content-Type in the HttpHeaders.Accept request header.

Link copied to clipboard
data class LocalPortRouteSelector(val port: Int) : RouteSelector

Evaluates a route against the port on which a call is received.

Link copied to clipboard

Evaluates a route against an optional query parameter value and captures its value, if found.

Link copied to clipboard
data class OrRouteSelector(val first: RouteSelector, val second: RouteSelector) : RouteSelector

Evaluates a route as a result of the OR operation using two other selectors.

Link copied to clipboard

Evaluates a route against a query parameter value and captures its value.

Link copied to clipboard

Evaluates a route against a constant path segment.

data class PathSegmentOptionalParameterRouteSelector(val name: String, val prefix: String? = null, val suffix: String? = null) : RouteSelector

Evaluates a route against an optional parameter path segment and captures its value, if any.

Link copied to clipboard
data class PathSegmentParameterRouteSelector(val name: String, val prefix: String? = null, val suffix: String? = null) : RouteSelector

Evaluates a route against a parameter path segment and captures its value.

Link copied to clipboard
Link copied to clipboard

A helper object for building instances of RouteSelector from path segments.

Link copied to clipboard
data class PathSegmentTailcardRouteSelector(val name: String = "", val prefix: String = "") : RouteSelector

Evaluates a route against any number of trailing path segments, and captures their values.

Link copied to clipboard

Evaluates a route against any single path segment.

Link copied to clipboard
class RootRouteSelector(rootPath: String = "") : RouteSelector

A selector for a routing root.

Link copied to clipboard
interface RootRouting : Routing

A builder for a routing tree root.

Link copied to clipboard
abstract class RouteSelector

Serves as the base type for routing selectors.

Link copied to clipboard

A result of a route evaluation against a call.

Link copied to clipboard
interface Routing

A builder for a routing tree.

Link copied to clipboard

A single act of communication between a client and server that is handled in RoutingRoot.

Link copied to clipboard
class RoutingContext(val call: RoutingCall)

The context of a RoutingHandler that is used to handle a RoutingCall.

Link copied to clipboard
typealias RoutingHandler = suspend RoutingContext.() -> Unit

A function that handles a RoutingCall.

Link copied to clipboard
open class RoutingNode(val parent: RoutingNode?, val selector: RouteSelector, val developmentMode: Boolean = false, val environment: ApplicationEnvironment) : ApplicationCallPipeline, Routing

Describes a node in a routing tree.

Link copied to clipboard

A parsed routing path. Consist of number of segments parts.

Link copied to clipboard
data class RoutingPathSegment(val value: String, val kind: RoutingPathSegmentKind)

A single routing path segment.

Link copied to clipboard

Possible routing path segment kinds.

Link copied to clipboard
class RoutingPipelineCall(val engineCall: PipelineCall, val route: RoutingNode, val coroutineContext: CoroutineContext, receivePipeline: ApplicationReceivePipeline, responsePipeline: ApplicationSendPipeline, val pathParameters: Parameters) : PipelineCall, CoroutineScope

An application call handled by RoutingRoot.

Link copied to clipboard

An application request handled by RoutingRoot.

Link copied to clipboard

An application response handled by RoutingRoot.

Link copied to clipboard

A client's request that can be handled in RoutingRoot. To learn how to handle incoming requests, see Handling requests.

Link copied to clipboard
class RoutingResolveContext(val routing: RoutingNode, val call: PipelineCall, tracers: List<(RoutingResolveTrace) -> Unit>)

Represents a context in which routing resolution is being performed

Link copied to clipboard

Represents a result of routing resolution.

Link copied to clipboard
class RoutingResolveTrace(val call: PipelineCall, val segments: List<String>)

Represents the trace of routing resolution process for diagnostics.

Link copied to clipboard
open class RoutingResolveTraceEntry(val route: RoutingNode, val segmentIndex: Int, var result: RoutingResolveResult? = null)

Represents a single entry in the RoutingResolveTrace.

Link copied to clipboard

A server's response that can be used to respond in RoutingRoot. To learn how to send responses inside route handlers, see Sending responses.

Link copied to clipboard
class RoutingRoot(val application: Application) : RoutingNode, RootRouting

A root routing node of an Application. You can learn more about routing in Ktor from Routing.

Link copied to clipboard

Evaluates a route against a single trailing slash.

Properties

Link copied to clipboard

Gets an Application for this RoutingNode by scanning the hierarchy to the root.

Link copied to clipboard

A plugin that enables ignoring a trailing slash when resolving URLs.

Functions

Link copied to clipboard
fun Routing.accept(vararg contentTypes: ContentType, build: Routing.() -> Unit): Routing

Builds a route to match requests with the HttpHeaders.Accept header matching any of the specified contentTypes.

Link copied to clipboard
fun Routing.contentType(contentType: ContentType, build: Routing.() -> Unit): Routing

Builds a route to match requests with the HttpHeaders.ContentType header matching the specified contentType.

Link copied to clipboard

Creates a routing entry for the specified path.

Link copied to clipboard

Builds a route to match DELETE requests.

Builds a route to match DELETE requests with the specified path.

Builds a route to match DELETE requests with the specified regex path. Named parameters from regex can be accessed via ApplicationCall.parameters.

Link copied to clipboard

Builds a route to match GET requests.

Builds a route to match GET requests with the specified path.

Builds a route to match GET requests with the specified regex path. Named parameters from regex can be accessed via ApplicationCall.parameters.

Link copied to clipboard

Return list of endpoints with handlers under this route.

Link copied to clipboard

Builds a route to match HEAD requests.

Builds a route to match HEAD requests with the specified path.

Builds a route to match HEAD requests with the specified regex path. Named parameters from regex can be accessed via ApplicationCall.parameters.

Link copied to clipboard
fun Routing.header(name: String, value: String, build: Routing.() -> Unit): Routing

Builds a route to match a header with the specified name and value.

Link copied to clipboard
fun Routing.host(host: String, port: Int = 0, build: Routing.() -> Unit): Routing

Creates a route to match a request's host and port. There are no any host resolutions/transformations applied to a host: a request host is treated as a string.

fun Routing.host(hosts: List<String>, ports: List<Int> = emptyList(), build: Routing.() -> Unit): Routing
fun Routing.host(hostPattern: Regex, port: Int = 0, build: Routing.() -> Unit): Routing

Creates a route to match a request host and port. There are no any host resolutions/transformations applied to a host: a request host is treated as a string.

fun Routing.host(hosts: List<String>, hostPatterns: List<Regex>, ports: List<Int> = emptyList(), build: Routing.() -> Unit): Routing

Creates a route to match s request host and port. There are no any host resolutions/transformations applied to a host: a request host is treated as a string.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun Routing.localPort(port: Int, build: Routing.() -> Unit): Routing

Creates a route to match a port on which a call was received.

Link copied to clipboard
fun Routing.method(method: HttpMethod, body: Routing.() -> Unit): Routing

Builds a route to match the specified HTTP method.

Link copied to clipboard
fun Routing.optionalParam(name: String, build: Routing.() -> Unit): Routing

Builds a route to capture an optional parameter with specified name, if it exists.

Link copied to clipboard

Builds a route to match OPTIONS requests.

Builds a route to match OPTIONS requests with the specified path.

Builds a route to match OPTIONS requests with the specified regex path. Named parameters from regex can be accessed via ApplicationCall.parameters.

Link copied to clipboard
fun Routing.param(name: String, build: Routing.() -> Unit): Routing

Builds a route to match a parameter with the specified name and captures its value.

fun Routing.param(name: String, value: String, build: Routing.() -> Unit): Routing

Builds a route to match a parameter with the specified name and value.

Link copied to clipboard

Builds a route to match PATCH requests.

@JvmName(name = "patchTyped")
inline fun <R : Any> Routing.patch(crossinline body: suspend RoutingContext.(R) -> Unit): Routing

Builds a route to match PATCH requests receiving a request body as content of the R type.

Builds a route to match PATCH requests with the specified path.

@JvmName(name = "patchTypedPath")
inline fun <R : Any> Routing.patch(path: String, crossinline body: suspend RoutingContext.(R) -> Unit): Routing

Builds a route to match PATCH requests with the specified path receiving a request body as content of the R type.

Builds a route to match PATCH requests with the specified regex path. Named parameters from regex can be accessed via ApplicationCall.parameters.

@JvmName(name = "patchTypedPath")
inline fun <R : Any> Routing.patch(path: Regex, crossinline body: suspend RoutingContext.(R) -> Unit): Routing

Builds a route to match PATCH requests with the specified regex path receiving a request body as content of the R type. Named parameters from regex can be accessed via ApplicationCall.parameters.

Link copied to clipboard
fun Routing.port(vararg ports: Int, build: Routing.() -> Unit): Routing

Creates a route to match a request port.

Link copied to clipboard

Builds a route to match POST requests.

@JvmName(name = "postTyped")
inline fun <R : Any> Routing.post(crossinline body: suspend RoutingContext.(R) -> Unit): Routing

Builds a route to match POST requests receiving a request body as content of the R type.

Builds a route to match POST requests with the specified path.

@JvmName(name = "postTypedPath")
inline fun <R : Any> Routing.post(path: String, crossinline body: suspend RoutingContext.(R) -> Unit): Routing

Builds a route to match POST requests with the specified path receiving a request body as content of the R type.

Builds a route to match POST requests with the specified regex path. Named parameters from regex can be accessed via ApplicationCall.parameters.

@JvmName(name = "postTypedPath")
inline fun <R : Any> Routing.post(path: Regex, crossinline body: suspend RoutingContext.(R) -> Unit): Routing

Builds a route to match POST requests with the specified regex path receiving a request body as content of the R type. Named parameters from regex can be accessed via ApplicationCall.parameters.

Link copied to clipboard

Builds a route to match PUT requests.

@JvmName(name = "putTyped")
inline fun <R : Any> Routing.put(crossinline body: suspend RoutingContext.(R) -> Unit): Routing

Builds a route to match PUT requests receiving a request body as content of the R type.

Builds a route to match PUT requests with the specified path.

@JvmName(name = "putTypedPath")
inline fun <R : Any> Routing.put(path: String, crossinline body: suspend RoutingContext.(R) -> Unit): Routing

Builds a route to match PUT requests with the specified path receiving a request body as content of the R type.

Builds a route to match PUT requests with the specified regex path. Named parameters from regex can be accessed via ApplicationCall.parameters.

@JvmName(name = "putTypedPath")
inline fun <R : Any> Routing.put(path: Regex, crossinline body: suspend RoutingContext.(R) -> Unit): Routing

Builds a route to match PUT requests with the specified regex path receiving a request body as content of the R type. Named parameters from regex can be accessed via ApplicationCall.parameters.

Link copied to clipboard
fun Routing.route(path: String, build: Routing.() -> Unit): Routing

Builds a route to match the specified path.

fun Routing.route(path: Regex, build: Routing.() -> Unit): Routing

Builds a route to match the specified regex path. Named parameters from regex can be accessed via ApplicationCall.parameters.

fun Routing.route(path: String, method: HttpMethod, build: Routing.() -> Unit): Routing

Builds a route to match the specified HTTP method and path.

fun Routing.route(path: Regex, method: HttpMethod, build: Routing.() -> Unit): Routing

Builds a route to match the specified HTTP method and regex path. Named parameters from regex can be accessed via ApplicationCall.parameters.

Link copied to clipboard
fun Application.routing(configuration: RootRouting.() -> Unit): RoutingRoot

Installs a RoutingRoot plugin for the this Application and runs a configuration script on it. You can learn more about routing in Ktor from Routing.