我正在尝试设计两个具有依赖性的不同资源之间的关系。场景是:
两个资源,第一个名为"account“,第二个名为"person”。
在我的API中," person“资源是真实世界中一个人的表示,带有姓名、年龄、性别、地址、电话等。Account是负责验证一个人的资源,就像登录一样。
因此,"person“资源的表示形式如下:
{
"id": "7828292",
"name": "Joseph Climber",
"email": "yourmail@email.com",
"gender": "M",
"telephones": {
"main": {
"number": "898987777"
},
"secondary": {
"number": "909099090"
},
"business": {
"number": "937363902"
}
},
"address": {
"rel": "address",
"href": "person/{ID}/address"
}
} "account“资源的表示形式如下:
{
"id": "login@email.com",
"tokenAccess": "5E69FAE25F4B4F3E8CC5DE09A8163520",
"link": {
"rel": "person",
"href": "person/{id}"
}
}我的问题是:当我创建一个新的人(帖子人)时,我没有办法验证新的人,在这种情况下,必须创建一个新的帐户来做这件事,所以这对API消费者来说似乎有点困惑,因为API不能自然地表达这种关系(好的API设计的基本概念)。
表示帐户和人员资源之间的这种依赖关系的最佳方式是什么?
发布于 2013-07-03 06:15:37
如果有人试图在没有访问令牌的情况下通过POST连接到/person,那么返回一个状态代码401 Unauthorized,其主体类似于:
{
"@type": "error",
"description": "You must be authenticated to POST to person. If you do not have an account, then POST to /account to get an access token."
}我想这对于使用API的开发人员来说已经足够直观了。
https://stackoverflow.com/questions/17413059
复制相似问题