1

如果站点在路径中有资源:

/things/27

是否有任何已发布的标准表明路径:

/things

因此,还应该有资源吗?

我已经与一位同事讨论过这个问题,并且来自 Unix 背景(并记得基于文件结构的 HTTP 服务器的旧dys)我倾向于回答是的,父资源是隐含的,并且父目录不应该是 404。

然而,我的同事认为,除非网站上某处有指向“/things”的特定链接,否则这条路径上不需要任何资源。

RFC2616 或其他 HTTP 标准文档中是否讨论过这个问题?是否有关于该主题的其他相关文档?

4

1 回答 1

1

If you're considering implementing hypermedia in your application to provide the client of a set of possible actions at a given point (links with URI's to other appropriate resources) then the /things URI is the ideal place to send a GET for these links.

Below is a sample result of a GET on the /things resource. The advantage of this approach is that the client can be coded to look for the Rel values in the Links instead having to "know" how to construct the URI's. Even when client does need to build to a URI, it can still coded for search for items like {searchTerm} in the Search link href to replace with an appropriate value.

   "Things": [
      {
         "Description": "Resource level properties that make sense to put here",
         "Count": 33,
         "Links": [
            {
               "Rel": "self",
               "Method": "GET",
               "Href": "http://yourDomain/things",
               "Title": "Things resource"
            }
         ]
      }
   ],
   "Navigation": [
      {
         "Links": [
            {
               "Rel": "GetItem",
               "Method": "GET",
               "Href": "http://yourDomain/things/{id}",
               "Title": "Get a single item"
            },
            {
               "Rel": "Search",
               "Method": "GET",
               "Href": "http://yourDomain/things/?searchTerm={searchTerm}&itemsPerCall={itemsPerCall}",
               "Title": "Search items per term"
            }
         ]
      }
   ]
于 2012-04-10T17:01:40.840 回答