api - 在 REST API 中使用 ?参数的问号?

标签 api rest structure

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 , 33245orders不是查询参数,它们是资源端点或 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/

相关文章:

C 结构错误 : Dereferencing pointer to an incomplete type

android - targetSdkVersion 和项目构建目标之间的区别

api - 有没有办法通过一次 Shopify API 调用来创建多个产品?

api - Z3的C API中 `Z3_mk_forall`和 `Z3_mk_forall_const`之间的区别?

java - 错误 :(229, 12) java : exception org. springframework.web.client.HttpStatusCodeException 已被捕获

c++ - 这个typedef是什么意思?

php - 使用 PHP 通过 WhatsApp API 发送消息

rest - 我可以在 CREATE 或 SET 上参数化标签和属性吗? (REST 和交易)

rest - DTO 和 API 资源有什么区别

c++ - 在C++中将一种结构类型分配给另一种类型