【发布时间】:2016-03-15 12:23:12
【问题描述】:
我正在设计一个 REST API。有一个实体Organization,它可能有一个父组织和多个子组织。
假设用户请求GET /organizations/1234。
我该怎么回复?
我可以使用这些其他组织的 URL。
{
"data": {
"name": "Microsoft",
"parent_organization": "http://api.myapi.asdfghj/organizations/1220",
"child_organizations": [
"http://api.myapi.asdfghj/organizations/1236",
"http://api.myapi.asdfghj/organizations/1214"
]
}
}
或者我可以使用他们的 ID
{
"data": {
"name": "Microsoft",
"parent_organization": 1220,
"child_organizations": [
1236,
1214
]
}
}
哪个更好?
如果它是具有完整 URL 的那个,我该如何大摇大摆地记录它?我是否只是将其设置为字符串,如下所示?
definitions:
Organization:
type: object
properties:
data:
type: object
properties:
name:
type: string
parent_organization:
type: string
format: url
child_organizations:
type: array
items:
type: string
format: url
POST /organizations 创建新用户怎么样?用户是否也应该将父项和子项指定为 url?
【问题讨论】: