joscha.alisch
04/10/2018, 5:50 PMimport org.http4k.contract.*
import org.http4k.core.*
import org.http4k.format.Jackson
import org.http4k.format.Jackson.auto
import org.http4k.routing.bind
import org.http4k.routing.routes
import org.http4k.server.Jetty
import org.http4k.server.asServer
data class MyDataClass(val something: String)
val requestBody = Body.auto<MyDataClass>().toLens()
fun main(args: Array<String>) {
routes(
"/api" bind contract(OpenApi(ApiInfo("My great API", "v1.0"), Jackson),"/route" meta {
body = requestBody
} bindContract Method.GET to ::handler)
).asServer(Jetty(5000)).start()
}
fun handler(request: Request): Response {
return Response(Status.OK)
}
gives me {
“swagger” : “2.0",
“info” : {
“title” : “My great API”,
“version” : “v1.0”,
“description” : “”
},
“basePath” : “/”,
“tags” : [ ],
“paths” : {
“/api/route” : {
“get” : {
“tags” : [ “/api” ],
“summary” : “<unknown>“,
“description” : null,
“produces” : [ ],
“consumes” : [ “application/json” ],
“parameters” : [ {
“in” : “body”,
“name” : “body”,
“description” : null,
“required” : true,
“type” : “object”
} ],
“responses” : { },
“supportedContentTypes” : [ ],
“security” : [ ]
}
}
},
“securityDefinitions” : { },
“definitions” : { }
}
dave
04/10/2018, 6:17 PMjoscha.alisch
04/10/2018, 6:19 PMreceiving(requestBody to MyDataClass("example"))
dave
04/10/2018, 6:35 PM