leonhardt
04/11/2025, 6:44 AMhttp4k-api-openapi
module. When using a path lens, I've got a route working when the lens is at the end of a route, but I'm stuck on how to place one in the middle of a route. Any tips?leonhardt
04/11/2025, 6:44 AMimport org.http4k.contract.contract
import org.http4k.contract.div
import org.http4k.contract.meta
import org.http4k.core.Method
import org.http4k.core.Response
import org.http4k.core.Status
import org.http4k.lens.Path
import org.http4k.lens.uuid
import org.http4k.routing.RoutingHttpHandler
val productIdPathLens = Path.uuid().of("productId")
fun createRoutes(): RoutingHttpHandler = contract {
// ✅ this route compiles
routes += "/v1/products" / productIdPathLens meta {
// ...
} bindContract Method.GET to { productId ->
{ request ->
// ...
Response(Status.OK)
}
}
// ❌ this route does not compile
routes += "/v1/products" / productIdPathLens / "status" meta {
// ...
} bindContract Method.POST to { productId ->
{ request ->
// ...
Response(Status.OK)
}
}
}
dave
04/11/2025, 8:27 AM{ productId, _ -> }
dave
04/11/2025, 8:27 AMAndrew O'Hara
04/12/2025, 2:32 AMleonhardt
04/14/2025, 6:24 AMdave
04/14/2025, 6:30 AMleonhardt
04/14/2025, 6:46 AM