如何使用参数定义 REST API

How to define REST API with to Parameter

我目前正在为一个项目开发 REST API。在这个过程中我应该搜索事件。我想做一个端点来搜索一段时间内的事件。即用from-to.

指定两个参数

对于搜索,您通常会执行 GET 操作。我的问题是现在在路径中指定两个参数是有意义的,还是我应该退回到 POST 操作来做类似的事情。

路径示例 /Events{From}{To}

使用多个参数是否可行?

如果您不对资源进行更改,则应使用 GET 操作。 More detailed explanation:

If you were writing a plain old RPC API call, they could technically interchangeable as long as the processing server side were no different between both calls. However, in order for the call to be RESTful, calling the endpoint via the GET method should have a distinct functionality (which is to get resource(s)) from the POST method (which is to create new resources).

具有多个参数的 GET 请求:/events?param1=value1&param2=value2

以数组作为参数的 GET 请求:/events?param=value1,value2,value3