2021-03-07 12:54:45 +00:00
|
|
|
from sanic import Sanic
|
|
|
|
from sanic.blueprints import Blueprint
|
|
|
|
from sanic.response import json
|
|
|
|
|
|
|
|
app = Sanic(name="blue-print-group-version-example")
|
|
|
|
|
|
|
|
bp1 = Blueprint(name="ultron", url_prefix="/ultron")
|
|
|
|
bp2 = Blueprint(name="vision", url_prefix="/vision", strict_slashes=None)
|
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
bpg = Blueprint.group(
|
|
|
|
bp1, bp2, url_prefix="/sentient/robot", version=1, strict_slashes=True
|
|
|
|
)
|
2021-03-07 12:54:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bp1.get("/name")
|
|
|
|
async def bp1_name(request):
|
|
|
|
"""This will expose an Endpoint GET /v1/sentient/robot/ultron/name"""
|
|
|
|
return json({"name": "Ultron"})
|
|
|
|
|
|
|
|
|
|
|
|
@bp2.get("/name")
|
|
|
|
async def bp2_name(request):
|
|
|
|
"""This will expose an Endpoint GET /v1/sentient/robot/vision/name"""
|
|
|
|
return json({"name": "vision"})
|
|
|
|
|
|
|
|
|
|
|
|
@bp2.get("/name", version=2)
|
|
|
|
async def bp2_revised_name(request):
|
|
|
|
"""This will expose an Endpoint GET /v2/sentient/robot/vision/name"""
|
|
|
|
return json({"name": "new vision"})
|
|
|
|
|
|
|
|
|
|
|
|
app.blueprint(bpg)
|
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
if __name__ == "__main__":
|
2021-03-07 12:54:45 +00:00
|
|
|
app.run(host="0.0.0.0", port=8000)
|