Thanks <@U4H0M349G>! It’s as simple as this: ```im...
# http4k
j
Thanks @dave! It’s as simple as this:
Copy code
import 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
Copy code
{
  “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” : { }
}
d
Yeah - you'll need to give http4k an example of your body to get this to work.
There should be an example of how to set the example request in the docs.
It can't infer to structure without an example
(ie from just the lens)
j
Ahh got it, so I need this for example:
receiving(requestBody to MyDataClass("example"))
Couldn’t find an example for that in the docs though
Anyways, thanks a lot - it works now 🙂
d
I'll check the docs for an example. Thanks 😀
👍 1