https://kotlinlang.org logo
#http4k
Title
# http4k
d

dave

03/10/2019, 4:47 PM
Hey peeps. Bit of an FYI about an API change. As a part of
v3.116.0
that we've just released, we've introduced a better API for
http4k-contract
which is more consistent with the way we define
route
meta. It looks like this:
Copy code
val router = "/basepath" bind contract {
    renderer = SimpleJson(Jackson)
    descriptionPath = "/swagger.json"
    security = ApiKey(Query.required("the_api_key"), { true })
    routes += "/descriptions" meta {
        summary = "endpoint"
        description = "some rambling description of what this thing actually does"
        operationId = "echoMessage"
        tags += Tag("tag1")
        queries += Query.boolean().required("b", "booleanQuery")
        receiving(Body.json("json").toLens())
    } bindContract GET to { Response(OK) }
}
We've deprecated the old
contract()
functions for the time being - they were getting a little out of hand with 8 or so overloaded (and all defaulted anyway) args, hence this change. Have a play and let us know if you like/hate it. Also in this release, there's a new
http4k-template-freemarker
module. 🙄
👍 2
f

fredrik.nordin

03/12/2019, 10:02 AM
I like the intention of cleaning that up, so that's all good. One thing I've noticed when reading through that code is that the language is a bit... off. There are effectively two "bind contract" sections in there, which is slightly confusing when read. Not sure how easy that is to change at this stage though.
d

dave

03/12/2019, 10:04 AM
hmm - good point. maybe we could make it
bindContractRoute
...
f

fredrik.nordin

03/12/2019, 10:22 AM
Naming is hard. So is creating a useful and understandable DSL.
4 Views