问题描述
我看看 API版本控制的最佳实践?,但不是非常相信答案,所以我会用更具体的例子再次质疑版本控制部分.我有两个URI(一个带有版本控制的一个,作为URI的一部分,一个没有):
http://xxxx/v1/user/123 -> favored solution in discussed thread http://xxxx/user/123
我怀疑第一个链接是否表达了休息的想法.我发现http://xxxx/v1/user/123混淆,因为它表明会有一个更高的API-very,例如http://xxxx/v2/user/123.但这在休息条款中没有意义,API版本本身是HTTP 1.0或1.1,它已在HTTP请求中发送.该REST资源中心视图与SOAP或Java接口等其他API接口(如果在合格名称中具有API版本).
在休息唯一的内容,版本传播有意义是该资源的表示(例如,添加或删除新字段).此版本控制属于内容协商的一部分,如:
http://xxx/user/123 + HTTP 'Accept' Header -> Content negotation through header http://xxx/user/123?v=1 -> for perma-links/hyperlinks一个人也可以争辩说,这种版本的内容协商可能是路径内部的URI的一部分,但我发现它是反直观的,因为您可以为相同资源的不同URI结束,并且必须保持重定向一些点.
suf-up:在休息URI中没有API版本控制,只有资源的表示的版本控制.表示版本-Info属于内容协商(作为QueryParam或HTTP'接受').
你觉得怎么样?在哪些事情中,您会不同意/同意?
推荐答案
我完全同意; URI表示身份,在介绍新版本时,身份不会更改.当然,可能有新的概念的新URI,并且现有的URI可能会重定向...但是包括URI中的"v2"闻到我的味道.
注意,这与休息无关,真的,从休息角度来看,它只是所有的角色.
其他推荐答案
您可以侦听X-API-Version http请求标头.如果标题存在,则服务器必须使用该版本的API.如果标题不存在,则服务器可以使用最新版本的API.
> GET /user/123 HTTP/1.1 > Host: xxx > X-API-Version: >=1.5.1, <2.0.0 > Accept: application/json > < HTTP/1.1 200 OK < X-API-Version: 1.6.12 < < { "user": { "id": 123, "name": "Bob Smith" } } <
其他推荐答案
对于它的价值,我同意曼努埃尔.你可以在这个问题如何发布版本休息uris
有很多人似乎不同意,但我不担心.只要您尊重超文本约束,您的URL看起来真的对您的客户没有大的影响.
问题描述
I had a look at Best practices for API versioning?, but am not quite convinced of the answer, so I am question the versioning part again with a more specific example. I am having two URIs (one with versioning as part of the URI and one without):
http://xxxx/v1/user/123 -> favored solution in discussed thread http://xxxx/user/123
I am having my doubts whether the first link expresses the idea of REST. I find http://xxxx/v1/user/123 confusing as it suggests that there will be a higher api-version someday like http://xxxx/v2/user/123. But this does not make sense in REST terms, the api version itself is HTTP 1.0 or 1.1, which is already sent inside the HTTP request. This REST resource centric view differs very from other api-interfaces like SOAP or Java-interfaces (where it is common to have api-versions in qualified names).
At REST the only thing where versioning makes sense is the representation of that resource (e.g. new fields are added or removed). This versioning belongs to the part of content-negotiation like:
http://xxx/user/123 + HTTP 'Accept' Header -> Content negotation through header http://xxx/user/123?v=1 -> for perma-links/hyperlinks
One could also argue that such version content-negotiation could be part of the URI inside the path, but I find it counter-intuitive, because you could end-up with different URIs for the same resource and have to maintain redirects at some point.
To sum-up: In REST URIs there is no api-versioning, only versioning of the resource's representation. Representation version-info belongs to content-negotiation (as queryParam or HTTP 'Accept').
What do you think? In which things would you disagree/agree?
推荐答案
I completely agree; a URI expresses identity, identity doesn't change when a new version is introduced. There might be new URIs for additional concepts, of course, and existing URIs might redirect … but including a "v2" in the URI smells RPCish to me.
Note that this has got nothing to do with REST, really, as from a REST perspective it's all just characters.
其他推荐答案
You could listen for an X-API-Version HTTP request header. If the header exists, then the server must use that version of the API. If the header does not exist, the server may use the latest version of the API.
> GET /user/123 HTTP/1.1 > Host: xxx > X-API-Version: >=1.5.1, <2.0.0 > Accept: application/json > < HTTP/1.1 200 OK < X-API-Version: 1.6.12 < < { "user": { "id": 123, "name": "Bob Smith" } } <
其他推荐答案
For what it is worth, I agree with you Manuel. You can see my reasoning in this question How to version REST URIs
There are plenty of people that seem to disagree but I would not worry. What your url looks like really does not have a big impact on your client as long as you respect the hypertext constraint.