在 this REST 教程网站,
什么时候,如果有的话,放置类似的东西是合适的
http://dev.m.gatech.edu/developer/USER_NAME/api/WIDGET_NAME/test?query=someparam
代替
http://dev.m.gatech.edu/developer/USER_NAME/api/WIDGET_NAME/test/someparam
或者
http://dev.m.gatech.edu/developer/USER_NAME/api/WIDGET_NAME/test/someparam/var1/param/var2/param
?
我在 SO 上看到了各种各样的东西。
最佳答案
您执行 GET 请求并需要传递一些参数的所有情况都应采用 ?param=value 的形式。
So is that first link up top, they are just wrong? Man, who can you trust these days :).
不,他们没有错。从那个站点拿这个例子
GET http://www.example.com/customers/33245/orders
在这里,
customers
, 33245
和 orders
不是查询参数,它们是资源端点或 uri 节点,因为它们在您的 restapitutorial.com 上调用它们如果你这样做
GET http://www.example.com/customers
你得到所有客户GET http://www.example.com/customers/33245
你得到客户 33245GET http://www.example.com/customers/33245/orders
你得到客户 33245 的订单它们都返回 0 个或多个资源。例如,如果您要对第一个查询应用查询,并且希望以 John 为名字获取所有客户,则可以执行此操作
GET http://www.example.com/customers?firstname=John
在你问题的最后一个例子中,它会写成
GET http://www.example.com/customers/firstname/john
相反,它是 错 在安宁方面。没有客户资源“firstname”,也没有名字资源“john”。有些客户的名字是“约翰”,你会用
GET http://www.example.com/customers?firstname=John
关于api - 在 REST API 中使用 ?参数的问号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30329173/