How are REST APIs versioned?

本文探讨了REST API版本控制的不同方法,包括通过URI、HTTP头部内容协商等方式,并总结了各大公共REST API的实际做法。

How are REST APIs versioned?

I am currently working on a REST API, and the question was raised, how are, and how should, REST APIs be versioned? Here are the results of my research.

It seems that there are a number of people recommending using Content-Negotiation (the HTTP “Accept:” header) for API versioning. However, none of the big public REST APIs I have looked at seem to be using this approach. They almost exclusively put the API version number in the URI, with the odd exception using a custom HTTP header. I am at somewhat of a loss to explain this disconnect.

Versioning strategies in discussions

POST VERSIONING
Stack Overflow 1 URI
Stack Overflow 2 Content Negotiation
blog post by Jeremy Content Negotiation
ycombinator discussion some opinions both ways
Stack Overflow 3 Content Negotiation
Stack Overflow 4 Content Negotiation
notmessenger blog post URI (against all headers)
Peter Williams Content Negotiation (strongly against URIs)  
Apigee Blog post on API versioning URI (some discussion)
Mark Nottingham REST versioning Recommending essentially versionless extensibility with a HATEOS approach
Nick Berardi on REST versioning URI
Restify “Accept-Version” header
Tom Maguire on REST versioning Content Negotiation
Nicholas Zakas on Rest Versioning URI
Steve Klabnik on Rest Versioning Content Negotiation + HATEOS
Luis Rei on Rest Versioning Content Negotiation with (;version=1.0)
kohana forum discussion on REST versioning Many Opinions
Troy Hunt on REST versioning Accept Header but also support custom header and URL
Paul Gear REST versioning Recommending essentially versionless extensibility with a HATEOS approach

Versioning strategies in popular REST APIs

API NAME VERSIONING EXAMPLE
Twillo date in URI  
Twitter URI  
Atlassian URI  
Google Search URI  
Github API URI/Media Type in v3 Intention is to remove versioning in favour of hypermedia – current application/vnd.github.v3
Azure Custom Header x-ms-version: 2011-08-18
Facebook URI/optional versioning graph.facebook.com/v1.0/me
Bing Maps URI  
Google maps unknown/strange  
Netflix URI parameter http://api.netflix.com/catalog/titles/series/70023522?v=1.5
Salesforce URI with version introspection {
“label”:”Winter ’10”
“version”:”20.0″,
“url”:”/services/data/v20.0″,
}
Google data API (youtube/spreadsheets/others) URI parameter or custom header “GData-Version: X.0″ or “v=X.0″
Flickr No versioning?  
Digg URI http://services.digg.com/2.0/comment.bury
Delicious URI https://api.del.icio.us/v1/posts/update
Last FM URI http://ws.audioscrobbler.com/2.0/
LinkedIn URI http://api.linkedin.com/v1/people/~/connections
Foursquare URI https://api.foursquare.com/v2/venues/40a55d80f964a52020f31ee3?oauth_token=XXX&v=YYYYMMDD
Freebase URI https://www.googleapis.com/freebase/v1/search?query=nirvana&indent=true
paypal parameter &VERSION=XX.0
Twitpic URI http://api.twitpic.com/2/upload.format
Etsy URI http://openapi.etsy.com/v2
Tropo URI https://api.tropo.com/1.0/sessions
Tumblr URI api.tumblr.com/v2/user/
openstreetmap URI and response body http://server/api/0.6/changeset/create
Ebay URI (I think) http://open.api.ebay.com/shopping?version=713
Reddit No versioning?  
Groupon URI http://api.groupon.com/v2/channels//deals{.json|.xml}
Geonames    
Wikipedia no versioning I think?  
Bitly URI https://api-ssl.bitly.com/v3/shorten
Disqus URI https://disqus.com/api/3.0/posts/remove.json
Yammer URI /api/v1
Drop Box URI https://api.dropbox.com/1/oauth/request_token
Amazon Simple Queue Service (Soap) URI Parameter and WSDL URI &Version=2011-10-01
Youtube data API versioning URI https://www.googleapis.com/youtube/v3

Versioning strategies in popular REST Libraries

LIBRARY NAME VERSIONING EXAMPLE
node-restify semver versioning in an accept-Version header accept-version: ~3
Jersey description of how to do Accept: header versioning in Jersey Accept: application/vnd.musicstore-v1+json
This entry was posted in  Uncategorized by  Tim Wood. Bookmark the  permalink.

23 THOUGHTS ON “HOW ARE REST APIS VERSIONED?

  1. Larry on  April 16, 2012 at 7:50 pm  said:

    The version of GitHub's API that you link to is deprecated. The new version v3 does its versioning via content negotiation whereas the old one had it in the URI. The new approach is documented here: http://developer.github.com/v3/mime/

    BTW, I found this very useful. Thanks!

  2. Pingback: How are REST APIs versioned? | Lexical Scope | nodeJS and Web APIs | Scoop.it

  3. Pingback: How are REST APIs versioned? | Lexical Scope | Modern web development | Scoop.it

  4. Pingback: How are REST APIs versioned?

  5. Great list! I’ve also found the following article to be useful for API versioning strategies: http://blog.apigee.com/detail/restful_api_design_tips_for_versioning/

  6. Pingback: REST Fundamentals | planetgeek.ch

  7. This is usually due to header-mangling and stripping. Mobile ISPs, proxy servers, some regular ISPs – they actually strip out headers from HTTP requests. So while content negotiation is a principally sound and proper way to do it, the realities of the world we live in require putting the version in the URI.

  8. Pingback: Revealing KijiREST: Resources | Kiji Community - Build Real-Time Scalable Data Applications on Apache HBase

  9. abhishek on  June 12, 2013 at 6:52 am  said:

    another reason why URI based versioning isnt right…

    http://bit.ly/14Vr4jc

    http://abhishek.pamecha.me/blogs/versioning-in-web-services/

  10. I think another reason is an implementation reason, because its easier and cleaner to have some web server work as a proxy to take /v1/ -> v1 service implementation instead of handling it in the service itself with a buch of ifs, like if(version==1) -> v1 of the service implementation

  11. Pingback: REST Fundamentals | bbv Blog

  12. Owen Rubel on  March 13, 2014 at 2:11 am  said:

    Dont get bogged down by purists. Do what is simple, scalable and practical. Just because it may not fit a spec doesn’t mean it’s not better for your needs or your clients needs. After all, the biggest API users are using URI after all and they serve MILLIONs a day

  13. Hello!
    When an API is obsoleted, what do you do normally when you want to block an older version? What mechanism do you use?
    Thanks.

    • Fred Flintstoneon  August 2, 2014 at 2:44 am  said:

      you are talking about deprecation and you need to version both the api form and the api function; in other words, you need to do versioning on the api application as well as on the apiObject that establishes how the api request/response is handled for each related uri.

  14. Pingback: Decoupling API Versions From Codebase Versions | Haddad's Journal

  15. Owen Rubel on  June 25, 2014 at 3:30 am  said:

    Found out after much reading that there is a good reason not to do versioning in header. forwards will not send header information properly and so it will often get lost. This is why alot of people after evaluation have stayed with versioning in the URI

    • BeosFreakon  May 15, 2015 at 1:24 pm  said:

      If that is the case then the forward is not being performed correctly. You would lose authorization, language, media types, etc.. Version belongs in the accept header. i.e. I accept this media type and this version.

  16. Pingback: El mekki anouar | API Versioning – Different Approaches to API Versioning (1)

  17. Pingback: RESTful APIs | LibreNMS development blog

  18. Pingback: Designer une API REST | OCTO talks !

Leave a Reply

内容概要:本文聚焦于针对采用卡尔曼滤波(KF)进行状态估计的电力系统,研究虚假数据注入攻击(FDIA)的机理与仿真方法,并通过Matlab代码实现完整的攻击模型。研究系统地分析了攻击者如何构造符合系统统计特性的隐蔽虚假数据,以规避传统不良数据检测机制,在不被察觉的情况下扭曲系统状态估计结果,进而威胁电力系统的运行监控与决策安全性。文中详细阐述了KF状态估计算法原理、攻击向量的数学建模与构造方法,并提供了可运行的Matlab代码,便于读者复现攻击过程,深入理解其内在机理与潜在风险。; 适合人群:具备电力系统分析、现代控制理论(特别是状态估计)基础知识,以及熟练Matlab编程能力的科研人员、高校研究生和从事电力系统网络安全防护工作的工程技术人员。; 使用场景及目标:①深入剖析基于卡尔曼滤波的电力系统状态估计的安全脆弱性;②研究虚假数据注入攻击的可行性、隐蔽性及危害程度;③为开发和验证新型攻击检测算法与防御策略提供精确的仿真攻击案例和测试平台。; 阅读建议:建议读者在充分掌握电力系统状态估计和卡尔曼滤波理论的基础上,仔细研读并运行所提供的Matlab代码,通过调整系统参数、噪声水平和攻击强度等变量,观察其对状态估计偏差的影响,从而深刻理解攻击的本质特征与防范的关键点。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值