休息标准:路径参数或请求参数 [英] Rest Standard: Path parameters or Request parameters
问题描述
我正在创建一个新的 REST 服务.
I am creating a new REST service.
将参数传递给 REST 服务的标准是什么.从 Java 中的不同 REST 实现,您可以将参数配置为路径的一部分或作为请求参数.例如,
What is the standard for passing parameters to REST services. From different REST implementations in Java, you can configure parameters as part of the path or as request parameters. For example,
路径参数http://www.rest.services.com/item/b
请求参数http://www.rest.services.com/get?item=b
有谁知道每种传递参数的方法的优缺点.似乎将参数作为路径的一部分传递似乎更符合 REST 协议的概念.也就是说,单个位置表示唯一的响应,对吗?
Does anyone know what the advantages/disadvantages for each method of passing parameters. It seems that passing the parameters as part of the path seems to coincide better with the notion of the REST protocol. That is, a single location signifies a unique response, correct?
推荐答案
作为一般规则,路径往往会被缓存,参数往往不会被缓存.
Paths tend to be cached, parameters tend to not be, as a general rule.
所以...
GET /customers/bob
对比
GET /customers?name=bob
第一个更有可能被缓存(假设正确的标头等),而后者可能不被缓存.
The first is more likely to be cached (assuming proper headers, etc.) whereas the latter is likely not to be cached.
这篇关于休息标准:路径参数或请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!