如何将多个 HTTP 动词映射到 HTTP4K 中的同一路径
How to map multiple HTTP Verbs to the same path in HTTP4K
我有一个类似于下面的路由,在 HTTP4K 中运行良好。然而,不得不重复调用 "/" bind 是很烦人的。我一直在寻找一种更简单的方法来表达 DSL,但似乎没有其他方法。有什么办法可以实现吗?
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()
有一个同名的便捷函数,它接受 Pair<Method, HttpHandler>
的可变参数,您应该能够删除前导 "/" 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()
我有一个类似于下面的路由,在 HTTP4K 中运行良好。然而,不得不重复调用 "/" bind 是很烦人的。我一直在寻找一种更简单的方法来表达 DSL,但似乎没有其他方法。有什么办法可以实现吗?
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()
有一个同名的便捷函数,它接受 Pair<Method, HttpHandler>
的可变参数,您应该能够删除前导 "/" 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()