我正在开发一个Web服务,所有中间更改都应进行版本控制(草稿),并且用户可以发布(实时保存他们的更改)。为了使用户继续引用较旧的版本(出于兼容性方面的考虑),用户也应该能够获得较旧的状态。
这是我目前的设计样子
+------------------+-------------------------------------------+--------------------------------------------------------------+-------------------------------------------------+
| action | request | response | state of resource |
+------------------+-------------------------------------------+--------------------------------------------------------------+-------------------------------------------------+
| create a post | post | status=201 id=123 and version=v1 | resource created with version v1 |
| update the post | put with id=123 and version=v1 | status=200 id=123 and version=v2 | new version of resource created with version=v2 |
| update the post | put with id=123 and version=v2 | status=200 id=123 and version=v3 | new version of resource created with version=v3 |
| update the post | put with id=123 version=v1 | status=409 and body indicating user is editing stale version | |
| publish the post | put with id=123 version=v2 action=publish | status=200 id=123 version=p1 (p indicating published) | new version created with version=p1 |
| get all versions | get list with id=123 status=all | status=200 and v1,v2,p1 in the body | no change |
+------------------+-------------------------------------------+--------------------------------------------------------------+-------------------------------------------------+
以上内容是否遵循其他架构?我担心的特定问题是
这里Put并不是幂等的,因为每次我们这样做都会创建一个新版本。
用户必须知道action = Publish才能发布文章。是否可以在put / get / post响应正文中的客户端IMO上获取此信息,我们应该告诉所有受支持的操作,例如:
{
"body": {...}
"actions": [
{
"type": "publish",
"uri": "/order/123/publish"
},
{
"type": "save",
"uri": "/order/123/save"
},
{
"type": "archive",
"uri": "/order/123/archive"
}
]
}
对细节过于草率了吗?
鉴于您使用的是波多黎各风格,我建议以下做法:
/order/123
。version-history
,latest-version
,predecessor-version
,successor-version
。仅使用所需的链接关系。不同的版本只是不同的资源。action
,您可以将资源标记为public
或draft
使用属性(例如isPublic
)。如果设置为true,则该版本将成为公共版本。具有该状态的最后一个“版本”将变为真正的“实时”版本。解决PUT幂等性问题
考虑到PUT
每次运行都会创建一个新的“版本”,它仍然是幂等的吗?我认为这很难回答。2个PUT请求的效果是否与1个相同?
好吧,如果您考虑使用HTTP访问日志,那么2个相同的PUT请求也将导致2个条目。我真的不知道该如何调和,但是我的想法是:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句