Nicola
09/25/2024, 10:27 AMs4nchez
09/25/2024, 10:40 AMimport org.http4k.contract.contract
import org.http4k.contract.div
import org.http4k.contract.meta
import org.http4k.core.Method.GET
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.lens.Path
fun main() {
val endpoint = "/api/v0.0.1" / Path.of("vendorType") / "healthcheck" meta {
summary = "xyz"
} bindContract GET to { _, vendor ->
{ _: Request ->
Response(OK).body("hello $vendor")
}
}
val app = contract { routes += endpoint }
app(Request(GET, "api/v0.0.1/acme/healthcheck")).also(::println) //returns 200
}
Nicola
09/25/2024, 10:41 AMNicola
09/26/2024, 8:46 AMval endpoint = "/api/v0.0.1" / Path.of("vendorType") / "health-check" meta {
summary = "Check the availability of the vendor service"
description = "Send a dummy request to the vendor service and reports its status"
} bindContract GET to { _, vendor ->
{ _ ->
healthCheckController(vendor, mavServiceClient)
}
}
val app = contract { routes += endpoint }
app(org.http4k.core.Request(GET, "/api/v0.0.1/acme/health-check")).also(::println) // Get 400 and message "Vendor type specified health-check is not valid"
Nicola
09/26/2024, 8:49 AMNicola
09/26/2024, 8:50 AMs4nchez
09/26/2024, 8:53 AMhealthCheckController
because the routing above works. You can try it by just returning Response(OK).body("hello $vendor")
as a test.Nicola
09/26/2024, 8:53 AMNicola
09/26/2024, 9:41 AMval endpoint = "/$apiPrefix" / Path.of("vendorType") / "health-check" meta {
summary = "Check the availability of the vendor service"
description = "Send a dummy request to the vendor service and reports its status"
} bindContract GET to { _, vendor ->
{ _ ->
Response(Status.OK).body("Hello $vendor") // healthCheckController(vendor, mavServiceClient)
}
}
val app = contract { routes += endpoint }
DebuggingFilters.PrintRequestAndResponse().then(app)(org.http4k.core.Request(GET, "/api/v0.0.1/acme/health-check")).also(::println)
Outputs:
***** REQUEST: GET: /api/v0.0.1/acme/health-check *****
GET /api/v0.0.1/acme/health-check HTTP/1.1
***** RESPONSE 200 to GET: /api/v0.0.1/acme/health-check *****
HTTP/1.1 200 OK
Hello health-check
HTTP/1.1 200 OK
Hello health-check
> Task :tests4nchez
09/26/2024, 9:43 AM} bindContract GET to { vendor, _ ->
Nicola
09/26/2024, 9:44 AMNicola
09/26/2024, 10:04 AMs4nchez
09/26/2024, 10:06 AM