【发布时间】:2017-03-29 23:09:59
【问题描述】:
我们目前有 4 种内容类型可能包含在交付中。在大约 8-12 个月内,我们可能会有另外 2-4 种内容类型。我现在正在开发一个公共 REST api,我想知道我是否可以以这样一种方式编写 api,以使未来的添加不需要版本提升?
目前我们认为delivery 会返回类似这样的 json 结果:
{
"dateDelivered": "2016-01-01",
"clientId": "000001",
"contentCounts" : {
"total" : 100,
"articles": 75,
"slideshows": 25
... // other content types as we add them
}
"content" : {
"articles" : "http://api.example.com/v0/deliveries/1234/content/articles",
"slideshows" : "http://api.example.com/v0/deliveries/1234/content/slideshows",
... // other content types as we add them
}
}
这将contentCounts 和content 定义为具有每个可用内容类型的可选属性的对象。我想我可以将它定义为每个内容类型的对象数组,但我看不出这会如何真正改变任何东西。
如果将来结果对象看起来更像这样,是否有任何理由成为重大更改:
{
"dateDelivered": "2016-01-01",
"clientId": "000001",
"contentCounts" : {
"total" : 150,
"articles": 75,
"slideshows": 25,
"events": 25,
"videos": 25
}
"content" : {
"articles" : "http://api.example.com/v0/deliveries/1234/content/articles",
"slideshows" : "http://api.example.com/v0/deliveries/1234/content/slideshows",
"events" : "http://api.example.com/v0/deliveries/1234/content/events",
"videos" : "http://api.example.com/v0/deliveries/1234/content/videos"
}
}
【问题讨论】:
-
不——我不会考虑将属性添加到对象作为重大更改。删除/移动/重命名/更改属性类型将被破坏。
-
但您可能会考虑拥有一个包含名称和 url 的内容数组
标签: rest