# 响应(Response)

所有的 响应函数 都必须返回一个 response 对象,中间件 可以自由选择是否返回 response 对象。

# 响应方式(Methods)

Sanic 内置了 9 种常用的返回类型,您可以通过以下方式中的任意一种快速生成返回对象。

    # 默认状态码(Default Status)

    响应的默认 HTTP 状态码是 200,如果您需要更改状态码,可以通过下面的方式进行更改:

    @app.post("/")
    async def create_new(request):
        new_thing = await do_create(request)
        return json({"created": True, "id": new_thing.thing_id}, status=201)
    
    MIT Licensed
    Copyright © 2018-present Sanic Community Organization

    ~ Made with ❤️ and ☕️ ~