我们目前有4种内容类型可能包含在交付中。在大约8-12个月内,我们可能会有另外2-4种内容类型。我现在正在开发一个公共REST API,并想知道我能否以这种方式编写API,以便将来的增加不需要版本冲突?我可以添加新的REST属性而不进行重大更改吗?
目前,我们正在考虑一个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"
}
}
不 - 我不会考虑添加属性作为一个突破性的变化对象。删除/移动/重命名/更改类型的属性将打破。 – cejast
但是你可能会考虑拥有一个名称为&url – Dijkgraaf