java - 休息 : Handling matrix style and template style parameter with same name in a request

标签 java spring rest web-services django-rest-framework

考虑以下请求

   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/

相关文章:

java - 在 Spring Boot 应用程序中使用 redis 创建存储库

web-services - 如何在服务器端对使用 JSON restful web 服务构建的 web 应用程序进行负载测试?

c# - 将表单数据发布到 MVC Core API

java - float 和 double 的不同值

Java - 以 netbeans 形式向按钮添加方法

mysql 中的 java.lang.NullPointerException

java - spring-boot-2.0.0.RELEASE 中缺少 SpringApplication.run 的特定重载

java - 我有 REST API 并想重用它来在同一台服务器上公开不同格式的 API

java - 新手尝试创建实例

java - Android Google Place API java.lang.NullPointerException 错误