【发布时间】:2016-12-22 23:19:08
【问题描述】:
我在 Mongo DB for Users 中有类似的结构。
{
"id": 112121
"name": "Strange",
"age": 27,
"type": "Manager"
"email" : "strage@gamil.com",
"items" : [
{
"id": "1001",
"name": "laptop",
"details": [
{
"attributeKey": "ManifaturedYear",
"attributeValue" : "2010"
},
{
"attributeKey": "EligibaleToDsipose",
"attributeValue" : "2018"
}
]
},
{
"id": "1002",
"name": "phone",
"details": [
{
"attributeKey": "ManifaturedYear",
"attributeValue" : "2010"
},
{
"attributeKey": "EligibaleToDsipose",
"attributeValue" : "2018"
}
]
}
]
}
我提供了一个安静的 URI 来操作这个资源。并有如下网址
创建
POST api/users
POST api/users/{id}/items e.g. api/user/12121/items
POST api/users/{id}/items/{id}/details e.g. api/user/23223/items/222/details
更新 |删除
[ PUT | DELETE ] api/users/{id}
[ PUT | DELETE ] api/users/{id}/items/{id}
[ PUT | DELETE ] api/users/{id}/items/{id}/details/{attributeKey}
我的问题是我如何支持获取请求
- 获取经理拥有的项目? A、B 或 C
A.获取 api/users/type/{type}/items 例如获取 api/users/type/Manager/items
B.获取 api/users/{type}/items 例如GET api/users/Manager/items # 与 id 冲突
C. GET api/users/items?type=Manager
- 如何使用电子邮件地址 abc@gmail.com 获取用户的项目
A.获取 api/users/email/abc@gamil.com/items
B. GET api/users/items?userEmail=abc@gmail.com
- 如何获取30岁以上用户的物品?
我在设计其余 URI 时可以参考的任何好的参考
【问题讨论】:
标签: mongodb rest restful-url