Introduction
Media type versioning helps servers and clients agree on which version of data format to use. It keeps APIs working smoothly when changes happen.
Jump into concepts and practice - no test required
Media type versioning helps servers and clients agree on which version of data format to use. It keeps APIs working smoothly when changes happen.
GET /resource HTTP/1.1
Accept: application/vnd.example.v1+jsonAccept: application/vnd.example.v1+json
Accept: application/vnd.example.v2+json
Content-Type: application/vnd.example.v1+json
This simple Flask app checks the Accept header to decide which version of greeting to send back.
from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/greeting') def greeting(): accept = request.headers.get('Accept', '') if 'vnd.example.v2+json' in accept: return jsonify(message='Hello from version 2!') elif 'vnd.example.v1+json' in accept: return jsonify(message='Hello from version 1!') else: return jsonify(message='Hello from default version!') if __name__ == '__main__': app.run(debug=True)
Always document your media type versions clearly for clients.
Use media type versioning to keep URLs clean and stable.
Clients must set the Accept header correctly to get the right version.
Media type versioning uses the Accept header to specify API version.
This helps servers send the right data format without changing URLs.
It keeps old and new clients working together smoothly.
Accept header to tell the server which media type and version it wants.Content-Type is for request body format, Authorization is for credentials, and User-Agent identifies the client software.Accept: application/vnd.example.v2+jsonapplication/vnd.example.v2+json. The .v2 part indicates version 2.v2 suffix is a common pattern to specify API version 2 in media type versioning.Accept: application/vnd.example.v1+json