具有相同的物体REST API,但光 [英] REST API having same object, but light
问题描述
我们正在建设一个REST API,我们希望返回相同的对象,但一个呼叫是一个光的版本(没有所有领域)
We are building a REST API and we want to return the same object, but one call is a 'light' version (without all the field)
什么是最好的做法是什么?
what is the best practice ?
第一种情况
- 完整版本: http://api.domain.com/myobject/ {} OBJECTID
- 轻版本:<一href=\"http://api.domain.com/myobject/\">http://api.domain.com/myobject/{objectId}?filter=light
- full version: http://api.domain.com/myobject/{objectId}
- light version: http://api.domain.com/myobject/{objectId}?filter=light
第二种情况
- 完整版本: http://api.domain.com/myobject/ {} OBJECTID /详情
- 轻型版本: http://api.domain.com/myobject/ {} OBJECTID
- full version: http://api.domain.com/myobject/{objectId}/details
- light version: http://api.domain.com/myobject/{objectId}
3的情况下
- 完整版本: http://api.domain.com/myobject/ {} OBJECTID充分= TRUE
- 轻型版本: http://api.domain.com/myobject/ {} OBJECTID
- full version: http://api.domain.com/myobject/{objectId}?full=true
- light version: http://api.domain.com/myobject/{objectId}
4的情况下?
一个REST API的文档资源的任何链接欢迎!
Any link to a documented resource of a REST API is welcome !
感谢。
推荐答案
在第一种情况和第3的情况下有一个URL被用来作为一个单一的资源和查询字符串用于请求该资源的特定视图的优势。它们之间的选择是一个品味的问题,但我倾向于preFER让所有的数据和保存的选项查看子集的默认值。
The 1st case and 3rd case have the advantage that one url is used for a single resource and the query string is used to request a particular view of that resource. Choosing between them is a matter of taste, but I tend to prefer a default of getting all the data and saving the options for viewing subsets.
这篇关于具有相同的物体REST API,但光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!