方式一:利用URL
HTTP GET:
https://haveibeenpwned.com/api/v2/breachedaccount/foo
方式二:利用用户自定义的request header
HTTP GET:
https://haveibeenpwned.com/api/breachedaccount/foo
api-version: 2
方式三:利用content type
HTTP GET:
https://haveibeenpwned.com/api/breachedaccount/foo
Accept: application/vnd.haveibeenpwned.v2+json
方式四:利用content type
HTTP GET:
https://haveibeenpwned.com/api/breachedaccount/foo
Accept: application/vnd.haveibeenpwned+json; version=2.0
这个方式和方式三的小不同的地方是,把版本号分离出来了。
方式五:利用URL里的parameter
HTTP GET:
https://haveibeenpwned.com/api/breachedaccount/foo?v=2
第二种方式用spring mvc实现最容易,也最简洁。
因为只要在Controler上用@RequestMapping标明版本即可。不用再去各种匹配,各种识别。
如果是自己写一个Annotation来识别的话,也要花些功夫,而且怎么无缝地转发到原有的Spring mvc的配置也是个问题。
@Controller
@RequestMapping(headers="apt-version=2")
public class TestControllerV2 {
}