thanks! now the reason i got here is that i was l...
# http4k
t
thanks! now the reason i got here is that i was looking to add an extension method to
ContractRoute
that would enable it to provide a client api with slightly less knowledge about http4k than
newRequest
currently does. for this i was looking to encapsulate the lens/marshalling of request/response - as an example (ignore the reckless cast/lack of null checks of the request lens):
Copy code
inline fun <IN, reified OUT : Any> ContractRoute.call(baseUrl: String, authToken: String, requestBody: IN): OUT {
        val request = this.newRequest(Uri.of(baseUrl))
            .with(this.meta.body as BiDiBodyLens<IN> of requestBody)
            .header("Authorization", "Bearer $authToken")
        val response = OkHttp()(request)
        return jacksonObjectMapper().readValue(response.bodyString())
    }
and then clients can call with
val response: MyReturnType = route.call(url, token, myRequest)
the response lenses aren’t available as currently they already get applied to the example when defining the meta - i can extend extend the HttpMessageMeta to keep it around (like we did for the example and my custom renderer) and reuse that. but i wanted to get your thoughts on the best way to do this as still bit of a kotlin newbie