Rest 如何将多个HTTP谓词映射到HTTP4K中的同一路径
我有一条类似于下面的路线,在HTTP4K中运行良好。但是,必须重复调用“/”bind,这很烦人。我一直在寻找一种更简单的方式来表达DSL,但其他方式似乎都不管用。有没有办法做到这一点Rest 如何将多个HTTP谓词映射到HTTP4K中的同一路径,rest,kotlin,http4k,Rest,Kotlin,Http4k,我有一条类似于下面的路线,在HTTP4K中运行良好。但是,必须重复调用“/”bind,这很烦人。我一直在寻找一种更简单的方式来表达DSL,但其他方式似乎都不管用。有没有办法做到这一点 routes( "/things" bind routes( "/" bind Method.GET to allThings, "/{id:.*}" bind routes ( "/" bind Method.GET to singleThing,
routes(
"/things" bind routes(
"/" bind Method.GET to allThings,
"/{id:.*}" bind routes (
"/" bind Method.GET to singleThing,
"/" bind Method.DELETE to deleteThing,
"/" bind Method.PUT to addOrUpdateThing
)
)
).asServer(Netty(8080))
.start()
有一个相同名称的方便函数,它接受一个
对的vararg
,您应该能够删除前导的“/”bind
,如下所示:
routes(
"/things" bind routes(
"/" bind Method.GET to allThings,
"/{id:.*}" bind routes(
Method.GET to singleThing,
Method.DELETE to deleteThing,
Method.PUT to addOrUpdateThing
)
)
).asServer(Netty(8080))
.start()