如何版本 REST URI [英] How to version REST URIs
本文介绍了如何版本 REST URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
版本 REST URI 的最佳方法是什么?目前,我们在 URI 本身中有一个版本号,即.
What is the best way to version REST URIs? Currently we have a version # in the URI itself, ie.
http://example.com/users/v4/1234/
对于此表示的第 4 版.
for version 4 of this representation.
版本是否属于查询字符串?即.
Does the version belong in the queryString? ie.
http://example.com/users/1234?version=4
或者版本控制是否最好以另一种方式完成?
Or is versioning best accomplished another way?
推荐答案
我认为最好将其作为 URI 本身的一部分(选项 1),因为 v4 标识的资源与 v3 不同.与第二个选项类似的查询参数最适合用于传递与请求相关的附加(查询)信息,而不是资源.
I would say making it part of the URI itself (option 1) is best because v4 identifies a different resource than v3. Query parameters like in your second option can be best used to pass-in additional (query) info related to the request, rather than the resource.
这篇关于如何版本 REST URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文