Hi everyone :wink: I know that http4k can generat...
# http4k
r
Hi everyone 😉 I know that http4k can generate
responseLens
and use
returning
to specify it in contract route. But I want to know is it possible to constraint and auto-marshalling for request? like
Copy code
data class LoginRequest(val email: String, val password: String) {
    init {
        require(EmailValidator.getInstance().isValid(email))
    }
}

val requestLens = Body.auto<LoginRequest>("Login essentials.")
fun handler(login: LoginRequest): HttpHandler =  { req: Request -> ... }

"/login" / Body.of(requestLens) meta {
   ...
} bindContract <http://Method.POST|Method.POST> to ::handler
Many thanks.
d
Absolutely - but the body isn't defined in the path as you've got above (And isn't injected as the path params are). Check out this example from the docs: https://www.http4k.org/guide/modules/contracts/
👍 1
r
thanks a lot!!! works like a charm.
👍 1