s4nchez
06/19/2018, 2:21 PMimport org.http4k.core.HttpHandler
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.routing.bind
import org.http4k.routing.routes
import org.http4k.routing.static
fun main(args: Array<String>) {
val existingApp: HttpHandler = routes(
"/legacy" bind { _: Request -> Response(OK).body("legacy") },
"/api" bind routes(
"v1" bind { _: Request -> Response(OK).body("v1") })
)
val handler = routes(
"/more" bind static(),
"/{any:.*}" bind existingApp
)
println(handler(Request(Method.GET, "/other")).bodyString()) //404
println(handler(Request(Method.GET, "/legacy")).bodyString()) //legacy
println(handler(Request(Method.GET, "/api/v1")).bodyString()) //v1
println(handler(Request(Method.GET, "/more/my-file.txt")).bodyString()) //shows content of file in /src/main/resources/my-file.txt
}