https://kotlinlang.org logo
Title
d

dave

03/09/2018, 6:51 AM
Normally we bind inside a with method call. Try calling it with the parens instead of infixed?
e

elifarley

03/09/2018, 6:55 AM
Same problem...
d

dave

03/09/2018, 8:44 AM
looks like it only works if you specify the input type
val hello = Header.required("foo").of<HttpMessage>("baa")
e

elifarley

03/09/2018, 10:51 AM
It did the trick. Now, how can solve this: I have
("/api/v1/${this.path.format(param)}" bindContract GET).let { route: RouteBinder<HttpHandler> ->
                handler.perform(route.newRequest().with(
                        Header.required("Service-Provider-Id") of "my-provider",
                        Header.required("Client-Realm-Id") of catalogName
                  ), this.responseLens as BodyLens<T>
                )
            }
I'd like to have:
fun <T : HttpMessage> serviceProviderIDOf(x: String) = Header.required("Service-Provider-Id").of<T>(x)

val setServiceProviderId = Filter { next ->
    { next(it).with(serviceProviderIDOf("myval")) }
}

    operator fun <T> invoke(handler: HttpHandler, catalogName: String, param: String): Pair<Status, T> =
            ("/api/v1/${this.path.format(param)}" bindContract GET).then(setServiceProviderId).let { route: RouteBinder<HttpHandler> ->
                handler.perform(route.newRequest().with(
                        Header.required("Client-Realm-Id") of catalogName
                  ), this.responseLens as BodyLens<T>
                )
            }
But it doesn't compile...
See image on main chat...
d

dave

03/09/2018, 11:04 AM
I think you're a little mixed up. bindContract doesn't return anything you can "then" to
e

elifarley

03/09/2018, 11:04 AM
yep, I'm a bit confused
d

dave

03/09/2018, 11:04 AM
bindContract will bind to a function that takes a string and returns an HttpHandler. so you need to attach filters to the response of that handler
e

elifarley

03/09/2018, 11:50 AM
I see...
The filter I created should be used to add a header to the request.
d

dave

03/09/2018, 1:42 PM
And you'll need to add it everytime - the bond method expects a function that returns a(decorated) httphandler
e

elifarley

03/09/2018, 2:30 PM
Didn't manage to make it work... will skip it for now