definition
Since Python 3.5, an enumerated type HTTPStatus has been defined in its standard library http, which contains commonly used http status codes. It is defined as follows:
Description
[100, 200) are "information" prompts, we rarely use them directly. The standard stipulates that the response with these status codes cannot have a body.
200 and above [200, 300) is a "success" response message. The status codes in this range are often used in server-side programming.
[300, 400): Redirection related.
[400, 500): indicates a client error.
[500...]: Indicates server error, generally not used directly in the program.
FastAPI simplified
A status is defined in the fastapi library, which can be used to more directly reference the above HTTP status codes in an enumerated manner. The related applications are as follows:
from fastapi import FastAPI, **status**
app = FastAPI()
@app.post("/items/", status_code=status.HTTP_201_CREATED)
async def create_item(name: str):
return {"name": name}