部分响应不是RESTful的 [英] Are partial response un-RESTful
问题描述
例如在回覆/ forum / {forum_id} / users时,我只是返回用户名和头像图片。
当有人想要有关用户的详细信息时,我发送{age,location,points_cored等}。
在尝试使用ember数据建模时,我们着迷于 https: //github.com/emberjs/data/issues/51
当开发者指出部分响应是针对RESTful设计的。但是在任何REST书籍或互联网上找不到任何此类信息。此外,我发现谷歌实际上在他们的RESTful API中使用部分响应,有很多人使用它。
所以想知道的是部分响应(如上所述)真的没有推荐使用RESTful服务或其设计选择问题。
与普遍的误解相反,REST并不要求您阅读并写出相同的确切资源。
CouchDB是一个非常好的例子。它可以处理:
- 可以创建,读取的对象(也称为文档) ,更新和删除,
- 和views
在您的情况下, / forums / 01a0 / users
将是一个视图,而
/ user / 99a7
将是一个对象。
During a discussion for designing our REST api's one of the fellow developer told that partial responses are not RESTful. e.g. While returning response for /forums/{forum_id}/users I am just returning user name and avatar pic. When somebody wants detailed info about user I send {age, location, points_scored etc. etc.}. While trying to model this using ember-data we landed up in the problem mentioned at https://github.com/emberjs/data/issues/51 Thats when the developer pointed out that partial responses are against RESTful design. But I could not find any such information in any of the REST books or on Internet. Moreover I found that google actually uses partial responses in their RESTful API's and there are many guys using it.
So wanted to know are partial responses (like the above) really not recommended for RESTful services or its just a design choice issue.
Contrary to a common misconception, REST does not oblige you to read and write the same exact resources.
CouchDB is a really good example for the way to go. It handles:
- "objects" (a.k.a. "documents") that can be created, read, updated, and deleted,
- and "views", which are computed from documents, that can only be read.
In your case, /forums/01a0/users
would be a "view", while /user/99a7
would be an "object".
这篇关于部分响应不是RESTful的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!