对于用户,我有类似的结构,如下所示。
{
"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"
}
]
}
]
}我提供了一个restful URI来操作这个资源。并具有如下URLS
创建
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}我的问题是我如何支持Get请求
A.获取api/user/type/{type}/items,例如获取api/user/type/Manager/ e.g. B.获取api/user/{type}/items,例如GET api/user/Manager/items#与id冲突 C.获取api/用户/项?type=Manager
A.获取api/users/电子邮件/abc@gamil.com/abc B.获取api/用户/项目?userEmail=abc@gmail.com
对于设计我的rest URI有什么好的参考吗?
发布于 2016-12-22 15:19:08
我的建议是,如果可能的话,将项目细分为顶级资源。/users/{id}仍将拥有该用户拥有的一组项。根据您的需要,您可能只将它们嵌入到用户响应中,而不是作为完整的表示形式嵌入它们。/items将是所有项的规范集合。这将为你提供以下资源:
/users
/users/{id}
/users/{id}/items
/items如果你这样做,那么:
1:GET /items?ownerType=Manager
2:GET /items?ownerEmail=abc@example.com (项的集合)-或- GET /users?email=abc@example.com (一个用户的集合)
3:GET /items?ownerOlderThan=30
https://stackoverflow.com/questions/41274853
复制相似问题