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

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
主站蜘蛛池模板: 西和县| 鄂伦春自治旗| 苍梧县| 敖汉旗| 民丰县| 西乡县| 蓝山县| 东海县| 营口市| 塔河县| 融水| 体育| 金川县| 郧西县| 杭州市| 施甸县| 鹿邑县| 巴彦淖尔市| 广河县| 金塔县| 武夷山市| 长顺县| 安庆市| 大荔县| 信阳市| 吉木乃县| 绍兴县| 大英县| 溧水县| 白玉县| 油尖旺区| 广宁县| 宁海县| 台北市| 松江区| 德惠市| 平顶山市| 昌都县| 德江县| 托克逊县| 博湖县|