【发布时间】:2017-10-17 23:48:10
【问题描述】:
我是 REST 和 HATEOAS 的新手,正在尝试创建一个简单的 API。
我有一个简单的一对多父子关系。
我创建的api如下:
家长:http://example.com/api/parents
家长:http://example.com/api/parents/123
父母的孩子:http://example.com/api/parents/123/children
父母的孩子:http://example.com/api/parents/123/children/456
我现在正在为所有回复添加超媒体链接。
每个响应都有一个self 链接,parent 响应有一个children 链接。
我应该在child 回复中添加parent 链接吗?
如果资源位于http://example.com/api/children/456,那么它当然需要链接。
但这就是指向子资源地址中父级的链接。
即http://example.com/api/parents/123 是 http://example.com/api/parents/123/children/456 的子串
【问题讨论】: