需要包含主体时,批量获取的REST API约定是什么?

时间:2018-06-22 22:03:34

标签: rest naming-conventions

我需要添加一个用于提取多个记录的API端点。通常,我会这样做:

GET /widgets?ids=1,2,3

但是,在这种情况下,URL的可能长度将超过2,083个字符的最大字符数。

为了解决此限制,我将需要在请求正文中使用POST请求:

{
  "ids": [1, 2, 3]
}

但是现在我的端点似乎不正确,我想不出一个好的命名约定:

POST /widgets
POST /get-widgets
POST /widgets-queries

在这种情况下,REST约定是什么?

1 个答案:

答案 0 :(得分:0)

我建议在GET端点上使用过滤器。该最大值也有些过时,当今大多数浏览器都支持2K以上的字符。

否则,对诸如Severe: WSSERVLET11: failed to parse runtime descriptor: com.sun.xml.ws.spi.db.DatabindingException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions javax.xml.transform.SourceLocator is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at javax.xml.transform.SourceLocator at public javax.xml.transform.SourceLocator serve.jaxws.TransformerConfigurationExceptionBean.locator at serve.jaxws.TransformerConfigurationExceptionBean Caused by: com.sun.xml.ws.spi.db.DatabindingException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions javax.xml.transform.SourceLocator is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at javax.xml.transform.SourceLocator at public javax.xml.transform.SourceLocator serve.jaxws.TransformerConfigurationExceptionBean.locator at serve.jaxws.TransformerConfigurationExceptionBean Severe: Exception while loading the app Severe: Undeployment failed for context /service2 Severe: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: javax.servlet.ServletException: com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to parse runtime descriptor: com.sun.xml.ws.spi.db.DatabindingException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions javax.xml.transform.SourceLocator is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at javax.xml.transform.SourceLocator at public javax.xml.transform.SourceLocator serve.jaxws.TransformerConfigurationExceptionBean.locator at serve.jaxws.TransformerConfigurationExceptionBean 之类的POST进行使用,并在正文中指定ID。

POST会向包含您的请求结果的URL返回/widget-queries。参见gooroo.io/GoorooTHINK/Article/16583/HTTP-Patterns --- Bouncer /

这也使请求可缓存。