Versioning

You can pass the version keyword to the route decorators, or to a blueprint initializer. It will result in the v{version} url prefix where {version} is the version number.

Per route

You can pass a version number to the routes directly.

  1. from sanic import response
  2. @app.route('/text', version=1)
  3. def handle_request(request):
  4. return response.text('Hello world! Version 1')
  5. @app.route('/text', version=2)
  6. def handle_request(request):
  7. return response.text('Hello world! Version 2')
  8. app.run(port=80)

Then with curl:

  1. curl localhost/v1/text
  2. curl localhost/v2/text

Global blueprint version

You can also pass a version number to the blueprint, which will apply to all routes.

  1. from sanic import response
  2. from sanic.blueprints import Blueprint
  3. bp = Blueprint('test', version=1)
  4. @bp.route('/html')
  5. def handle_request(request):
  6. return response.html('<p>Hello world!</p>')

Then with curl:

  1. curl localhost/v1/html