Rafael Diaz
10/05/2025, 12:59 AMList<ContractRoute>. However, I'm ending up with the type List<Pair<ContractRouteSpec2<Int, String>.Binder, (Request) -> Response>> when I add lenses to the route path.
I want to add the list of routes to an api contract, which accepts the former type but not the latter, so I was wondering how I could fix it.
More details inside:
Edit: Found the solution.
https://stackoverflow.com/questions/53278208/how-do-you-model-a-path-parameter-in-the-middle-with-http4kRafael Diaz
10/05/2025, 12:59 AMval api = contract {
routes += merchantItemController.routes
}
But it states:
None of the following candidates is applicable:
fun plusAssign(t: ContractRoute): Unit
fun plusAssign(t: Collection<ContractRoute>): Unit
Now I realized that that was causes the List<Pair...> is adding a lenses to the route.
This route with a lens is the type List<Pair<ContractRouteSpec2<Int, String>.Binder, (Request) -> Response>> :
val routes = listOf(
"/merchants" / merchantIdLens / "items" bindContract Method.GET to
{ id: Int ->
{ _: Request ->
Response(OK)
}
}
)
Whereas route without a lens is the type `List<ContractRoute>`:
```val routes = listOf(
"/merchants" / "items" bindContract Method.GET to
{ _: Request ->
Response(OK)
}
)Rafael Diaz
10/05/2025, 1:01 AMRafael Diaz
10/05/2025, 4:57 AMval routes = listOf(
"/merchants" / merchantIdLens / "items" bindContract Method.GET to
{ id, _ ->
{ _: Request ->
Response(OK)
}
}
)
Source:
https://stackoverflow.com/questions/53278208/how-do-you-model-a-path-parameter-in-the-middle-with-http4kdave
10/05/2025, 4:03 PM