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

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
主站蜘蛛池模板: 大竹县| 全南县| 临沂市| 通江县| 涟水县| 宁陕县| 泰州市| 乐昌市| 尚义县| 武平县| 砀山县| 衡阳县| 中江县| 乌鲁木齐县| 丰台区| 罗甸县| 神木县| 合江县| 雅安市| 洛南县| 隆林| 长丰县| 韩城市| 广西| 汽车| 岐山县| 疏勒县| 新疆| 诏安县| 阜南县| 奉化市| 苏尼特右旗| 合江县| 泗水县| 海宁市| 湘潭县| 资溪县| 开化县| 宕昌县| 全州县| 都昌县|