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

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
主站蜘蛛池模板: 藁城市| 化德县| 大埔区| 太湖县| 馆陶县| 西吉县| 犍为县| 湘阴县| 昔阳县| 文昌市| 蕉岭县| 芜湖市| 屯门区| 蕉岭县| 盘山县| 长阳| 安远县| 新巴尔虎右旗| 鄄城县| 油尖旺区| 邵东县| 汨罗市| 出国| 隆回县| 梓潼县| 龙胜| 南华县| 定州市| 玉环县| 灵川县| 康马县| 庆城县| 高雄市| 博乐市| 依兰县| 澳门| 来凤县| 阿尔山市| 江津市| 璧山县| 丰顺县|