Package-level declarations

Types

Link copied to clipboard
class PathMethod(path: String, method: Method)
Link copied to clipboard
Link copied to clipboard
fun interface ResourceLoader

Looks up contents of a resource path.

Link copied to clipboard
Link copied to clipboard
data class RoutedRequest(delegate: Request, val xUriTemplate: UriTemplate) : Request, RequestWithRoute
Link copied to clipboard
class RoutedResponse(delegate: Response, val xUriTemplate: UriTemplate) : Response, ResponseWithRoute
Link copied to clipboard
interface Router

Matches requests for routing purposes.

Link copied to clipboard
data class RouterDescription(val description: String, val children: List<RouterDescription> = listOf())
Link copied to clipboard

The result of a matching operation. May or may not contain a matched HttpHandler.

Link copied to clipboard

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

Link copied to clipboard
data class StaticRoutingHttpHandler(pathSegments: String, resourceLoader: ResourceLoader, extraFileExtensionToContentTypes: Map<String, ContentType>, filter: Filter = Filter.NoOp) : RoutingHttpHandler

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun Method.and(that: Router): Router
infix fun Router.and(that: Router): Router
Link copied to clipboard

fun (Request) -> Boolean.asRouter(description: String = unavailable.description): Router

Convert any predicate on a request into a router

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
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
fun Request.path(name: String): String?
Link copied to clipboard
fun queries(vararg names: String): Router

Ensure all queries are present

Link copied to clipboard
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().