api

http4k / org.http4k.routing

Package org.http4k.routing

Code for routing HTTP messages inside server implementations.

Types

Name Summary
PathMethod class PathMethod
ResourceLoader interface ResourceLoader
RoutedRequest data class RoutedRequest : Request
RoutedResponse class RoutedResponse : Response
Router Matches requests for routing purposes.interface Router
RouterDescription data class RouterDescription
RouterMatch The result of a matching operation. May or may not contain a matched HttpHandler.sealed class RouterMatch : Comparable<RouterMatch>
RoutingHttpHandler Composite HttpHandler which can potentially service many different URL patterns. Should return a 404 Response if it cannot service a particular Request.interface RoutingHttpHandler : Router, HttpHandler
RoutingSseHandler interface RoutingSseHandler : SseHandler
RoutingWsHandler interface RoutingWsHandler : WsHandler

Extensions for External Classes

Name Summary
kotlin.Function1  
kotlin.String  

Properties

Name Summary
Fallback val Fallback: Router

Functions

Name Summary
<no name provided> Looks up contents of a resource path.fun <no name provided>(): Unit
and fun Method.and(that: Router): Router
infix fun Router.and(that: Router): Router
asRouter fun Method.asRouter(): Router
bind infix fun Method.bind(routingHandler: RoutingHttpHandler): RoutingHttpHandler
infix fun Method.bind(httpHandler: HttpHandler): RoutingHttpHandler
infix fun Router.bind(handler: HttpHandler): RoutingHttpHandler
infix fun Router.bind(handler: RoutingHttpHandler): RoutingHttpHandler
body Ensure body matches predicatefun body(predicate: (Body) -> Boolean): Router
Ensure body string matches predicatefun body(predicate: (String) -> Boolean): Router
graphQL Routing plugin for GraphQL handling.fun graphQL(handler: GraphQLHandler, badRequestFn: (LensFailure) -> Response = { Response(BAD_REQUEST) }): RoutingHttpHandler
Routing plugin for GraphQL handling with contextual data.fun <T> graphQL(handler: GraphQLWithContextHandler<T>, getContext: (Request) -> T, badRequestFn: (LensFailure) -> Response = { Response(BAD_REQUEST) }): RoutingHttpHandler
header Apply routing predicate to a headerfun header(name: String, predicate: (String) -> Boolean): Router
fun header(name: String, value: String): Router
headers Ensure all headers are presentfun headers(vararg names: String): Router
path fun Request.path(name: String): String?
queries Ensure all queries are presentfun queries(vararg names: String): Router
query Apply routing predicate to a queryfun query(name: String, predicate: (String) -> Boolean): Router
fun query(name: String, value: String): Router
reverseProxy Simple Reverse Proxy which will split and direct traffic to the appropriate HttpHandler based on the content of the Host headerfun reverseProxy(vararg hostToHandler: Pair<String, HttpHandler>): RoutingHttpHandler
routes fun routes(vararg list: Pair<Method, HttpHandler>): RoutingHttpHandler
fun routes(vararg list: RoutingHttpHandler): RoutingHttpHandler
singlePageApp 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).fun singlePageApp(resourceLoader: ResourceLoader = ResourceLoader.Classpath("/public"), vararg extraFileExtensionToContentTypes: Pair<String, ContentType>): RoutingHttpHandler
sse fun sse(sse: SseConsumer): SseHandler
fun sse(vararg list: RoutingSseHandler): RoutingSseHandler
static 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.fun static(resourceLoader: ResourceLoader = Classpath(), vararg extraFileExtensionToContentTypes: Pair<String, ContentType>): RoutingHttpHandler
websockets fun websockets(ws: WsConsumer): WsHandler
fun websockets(vararg list: RoutingWsHandler): RoutingWsHandler