考虑以下请求
GET http://localhost:8080/app/{id}/details;id=some-value-here
在上述请求中,有一个名为id
的模板样式参数和一个名为id=some-value-here
的矩阵类型参数名称/值。
在处理此类请求时,API 的行为应该是什么?
- 通过处理重复的参数键照常服务请求?因为即使参数键相同,但它们的路径不同。一种是模板样式,另一种是矩阵样式。
- 拒绝请求,称参数名称存在冲突?
- 有任何 HTTP RFC 指导此类冲突解决吗?
最佳答案
在 RFC 中找到答案。
根据 RFC 6570特别是对于 URI 模板,section 3.2.1 。变量扩展表示以下内容(摘录)
If a variable appears more than once in an expression or within multiple expressions of a URI Template, the value of that variable MUST remain static throughout the expansion process (i.e., the variable must have the same value for the purpose of calculating each expansion).
这意味着,处理请求,但保留在 URI 扩展过程中遇到的 id
第一个值。
例如,
GET http://localhost:8080/app/{id}/details;id=some-value-here
如果 id
为 1,则扩展应该为
GET http://localhost:8080/app/1/details;id=1
关于java - 休息 : Handling matrix style and template style parameter with same name in a request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54671646/