Are partial response un-RESTful

2019-07-12 19:00发布

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.

标签: rest ember.js
1条回答
Bombasti
2楼-- · 2019-07-12 19:41

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".

查看更多
登录 后发表回答