Bear MAN
11/16/2022, 7:25 AMhttp4k-contract// this route has a dynamic path segment
fun greetRoute(): ContractRoute {
    // these lenses define the dynamic parts of the request that will be used in processing
    val ageQuery = <http://Query.int|Query.int>().required("age")
    val stringBody = Body.string(TEXT_PLAIN).toLens()
    // this specifies the route contract, with the desired contract of path, headers, queries and body parameters.
    val spec = "/greet" / Path.of("name") meta {
        summary = "tells the user hello!"
        queries += ageQuery
        receiving(stringBody)
    } bindContract GET
    // the this function will dynamically supply a new HttpHandler for each call. The number of parameters
    // matches the number of dynamic sections in the path (1)
    fun greet(nameFromPath: String): HttpHandler = { request: Request ->
        val age = ageQuery(request)
        val sentMessage = stringBody(request)
        Response(OK).with(stringBody of "hello $nameFromPath you are $age. You sent $sentMessage")
    }
    return spec to ::greet
}greet// this route has a dynamic path segment
fun greetRoute(): ContractRoute {
    // these lenses define the dynamic parts of the request that will be used in processing
    val ageQuery = <http://Query.int|Query.int>().required("age")
    val stringBody = Body.string(TEXT_PLAIN).toLens()
    // this specifies the route contract, with the desired contract of path, headers, queries and body parameters.
    val spec = "/greet" / Path.of("name") / "foo" meta {
        summary = "tells the user hello!"
        queries += ageQuery
        receiving(stringBody)
    } bindContract GET
    // the this function will dynamically supply a new HttpHandler for each call. The number of parameters
    // matches the number of dynamic sections in the path (1)
    fun greet(nameFromPath: String, foo: String): HttpHandler = { request: Request ->
        val age = ageQuery(request)
        val sentMessage = stringBody(request)
        Response(OK).with(stringBody of "hello $nameFromPath you are $age. You sent $sentMessage")
    }
    return spec to ::greet
}foo"foo"ContractRouteSpec2foo: Stringgreet_: Stringfoo: Stringdave
11/16/2022, 7:39 AMBear MAN
11/16/2022, 8:18 AMfoo: String_: Stringdave
11/16/2022, 8:19 AMBear MAN
11/16/2022, 8:36 AM// this route has a dynamic path segment
fun greetRoute(): ContractRoute {
    // these lenses define the dynamic parts of the request that will be used in processing
    val ageQuery = <http://Query.int|Query.int>().required("age")
    val stringBody = Body.string(TEXT_PLAIN).toLens()
    val namePath = Path.of("name")
    // this specifies the route contract, with the desired contract of path, headers, queries and body parameters.
    val spec = "/greet/{name}/foo" meta {
        summary = "tells the user hello!"
        queries += ageQuery
        queries += namePath
        receiving(stringBody)
    } bindContract GET
    // the this function will dynamically supply a new HttpHandler for each call. The number of parameters
    // matches the number of dynamic sections in the path (1)
    fun greet(): HttpHandler = { request: Request ->
        val name = namePath(request)
        val age = ageQuery(request)
        val sentMessage = stringBody(request)
        Response(OK).with(stringBody of "hello $name you are $age. You sent $sentMessage")
    }
    return spec to ::greet
}dave
11/16/2022, 8:38 AMBear MAN
11/16/2022, 9:04 AM_: String_: String