官术网_书友最值得收藏!

Versioning on media types

Another approach to versioning is using MIME types to include the API version. In short, API producers register these MIME types on their backend and then the consumers need to include accept and content-type headers.

The following code lets you use an additional header:

GET https://<HOST>/orders/1325 HTTP/1.1
Accept: application/json
Version: 1

GET https://<HOST>/orders/1325 HTTP/1.1
Accept: application/json
Version: 2

GET https://<HOST>/orders/1325 HTTP/1.1
Accept: application/json
Version: 3

The following code lets you use an additional field in the accept/content-type header:

GET https://<HOST>/orders/1325 HTTP/1.1
Accept: application/json; version=1

GET https://<HOST>/orders/1325 HTTP/1.1
Accept: application/json; version=2

GET https://<HOST>/orders/1325 HTTP/1.1
Accept: application/json; version=3

The following code lets you use a Media type:

GET https://<HOST>/orders/1325 HTTP/1.1
Accept: application/vnd.<host>.orders.v1+json

GET https://<HOST>/orders/1325 HTTP/1.1
Accept: application/vnd.<host>.orders.v2+json

GET https://<HOST>/orders/1325 HTTP/1.1
Accept: application/vnd.<host>.orders.v3+json
主站蜘蛛池模板: 鹰潭市| 武定县| 伊春市| 开江县| 遵义市| 平昌县| 桃江县| 深州市| 黔南| 安图县| 灵石县| 曲麻莱县| 加查县| 新乡市| 台南市| 东安县| 新巴尔虎右旗| 密云县| 县级市| 乌拉特前旗| 秦安县| 永年县| 贡觉县| 丰城市| 崇左市| 吉木乃县| 阳新县| 华阴市| 临猗县| 胶州市| 邓州市| 常宁市| 内黄县| 株洲市| 沙洋县| 余干县| 二连浩特市| 华阴市| 忻城县| 建阳市| 邢台市|