原文链接:https://sanicframework.org/en/guide/basics/handlers.html
def i_am_a_handler(request):
return HTTPResponse()
async def i_am_ALSO_a_handler(request):
return HTTPResponse()
from sanic.response import text
@app.get("/foo")
async def foo_handler(request):
return text("I said foo!")
from sanic.response import text
@app.get("/foo")
async def foo_handler(request):
return text("I said foo!")
import time
@app.get("/sync")
def sync_handler(request):
time.sleep(0.1)
return text("Done.")
@app.get("/async")
async def async_handler(request):
await asyncio.sleep(0.1)
return text("Done.")
from sanic.response import HTTPResponse, text
from sanic.request import Request
@app.get("/typed")
async def typed_handler(request: Request) -> HTTPResponse:
return text("Done.")