Package-level declarations

Types

Link copied to clipboard
Link copied to clipboard
data class PathMethod(val path: String, val method: Method)
Link copied to clipboard
data class RequestWithContext(val delegate: Request, val context: Map<String, Any?> = emptyMap()) : Request, RoutedMessage
Link copied to clipboard
fun interface ResourceLoader

Looks up contents of a resource path.

Link copied to clipboard
data class ResponseWithContext(val delegate: Response, val context: Map<String, Any> = emptyMap()) : Response, RoutedMessage
Link copied to clipboard
interface RoutedMessage
Link copied to clipboard
interface RouteMatcher<R, F>
Link copied to clipboard
interface Router
Link copied to clipboard
data class RouterDescription(val description: String)
Link copied to clipboard
abstract class RoutingHandler<R, F, Self : RouteMatcher<R, F>>(val routes: List<RouteMatcher<R, F>>, copy: (List<RouteMatcher<R, F>>) -> Self) : Function1<Request, R> , RouteMatcher<R, F>

Composite handler which can potentially service many different URL patterns. Should return a specified Response if it cannot service a particular Request.

Link copied to clipboard
data class RoutingMatch<R>(priority: Int, description: RouterDescription, handler: (Request) -> R) : Comparable<RoutingMatch<R>> , Function1<Request, R>
Link copied to clipboard
sealed interface RoutingResult
Link copied to clipboard
data class SimpleRouteMatcher(router: Router, handler: HttpHandler, filter: Filter = Filter.NoOp) : RouteMatcher<Response, Filter>
Link copied to clipboard
data class StaticRouteMatcher(pathSegments: String, resourceLoader: ResourceLoader, extraFileExtensionToContentTypes: Map<String, ContentType>, router: Router = All, filter: Filter = Filter.NoOp) : RouteMatcher<Response, Filter>
Link copied to clipboard
class TemplatedHttpRoute(uriTemplate: UriTemplate, handler: HttpHandler, router: Router = All, filter: Filter = Filter.NoOp) : TemplatedRoute<Response, Filter, TemplatedHttpRoute>
Link copied to clipboard
abstract class TemplatedRoute<R, F : ((Request) -> R) -> (Request) -> R, Self : RouteMatcher<R, F>>(uriTemplate: UriTemplate, handler: (Request) -> R, router: Router, filter: F, responseFor: (Status) -> R, addUriTemplateFilter: ((Request) -> R) -> (Request) -> R) : RouteMatcher<R, F>

Applies the generic templating routing logic regardless of protocol

Properties

Link copied to clipboard
val All: Router
Link copied to clipboard

Functions

Link copied to clipboard
infix fun String.accepting(contentType: ContentType): Router

Ensure the request is accepting a specific content type

Link copied to clipboard
infix fun String.and(router: Router): Router

Bind a path and another router together

fun Method.and(router: Router): Router
fun Router.and(other: Router): Router
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
@JvmName(name = "bodyMatches")
fun body(fn: (String) -> Boolean): Router

Ensure body string matches predicate

fun body(fn: (Body) -> Boolean): Router

Ensure body matches predicate

Link copied to clipboard
fun header(name: String, fn: (String) -> Boolean): Router
fun header(name: String, value: String): Router

Apply routing predicate to a header

Link copied to clipboard
fun headers(vararg names: String): Router

Ensure all headers are present

Link copied to clipboard
Link copied to clipboard
fun Router.or(other: Router): Router
Link copied to clipboard
fun Request.path(name: String): String?
Link copied to clipboard
fun queries(vararg names: String): Router

Ensure all queries are present and not null

Link copied to clipboard

Ensure all queries are present and match what is in the Uri

Link copied to clipboard
fun query(name: String): Router

Ensure query is present - even with no value

fun query(name: String, fn: (String) -> Boolean): Router
fun query(name: String, value: String): Router

Apply routing predicate to a query

Link copied to clipboard
fun reverseProxy(vararg hostToHandler: Pair<String, HttpHandler>): HttpHandler

Simple Reverse Proxy which will split and direct traffic to the appropriate HttpHandler based on the content of the Host header

Link copied to clipboard

Simple Reverse Proxy. Exposes routing.

Link copied to clipboard
Link copied to clipboard
fun singlePageApp(resourceLoader: ResourceLoader = ResourceLoader.Classpath("/public"), vararg extraFileExtensionToContentTypes: Pair<String, ContentType>): RoutingHttpHandler

For SPAs we serve static content as usual, or fall back to the index page. The resource loader is configured to look at /public package (on the Classpath).

Link copied to clipboard
fun static(resourceLoader: ResourceLoader = Classpath(), vararg extraFileExtensionToContentTypes: Pair<String, ContentType>): RoutingHttpHandler

Serve static content using the passed ResourceLoader. Note that for security, by default ONLY mime-types registered in mime.types (resource file) will be served. All other types are registered as application/octet-stream and are not served.

Link copied to clipboard

Serve WebJar contents from the classpath. Just install the dependencies and add this line to your routes().