原文链接:https://sanicframework.org/en/guide/basics/handlers.html

    1. def i_am_a_handler(request):
    2. return HTTPResponse()
    3. async def i_am_ALSO_a_handler(request):
    4. return HTTPResponse()
    1. from sanic.response import text
    2. @app.get("/foo")
    3. async def foo_handler(request):
    4. return text("I said foo!")
    1. from sanic.response import text
    2. @app.get("/foo")
    3. async def foo_handler(request):
    4. return text("I said foo!")
    1. import time
    2. @app.get("/sync")
    3. def sync_handler(request):
    4. time.sleep(0.1)
    5. return text("Done.")
    1. @app.get("/async")
    2. async def async_handler(request):
    3. await asyncio.sleep(0.1)
    4. return text("Done.")
    1. from sanic.response import HTTPResponse, text
    2. from sanic.request import Request
    3. @app.get("/typed")
    4. async def typed_handler(request: Request) -> HTTPResponse:
    5. return text("Done.")