Tutorial - User Guide - Intro - FastAPI
fastAPI refers to HTTP methods as operations. This is because the OpenAPI documentation and schema refer to HTTP methods as operations, so they match the way they call HTTP methods. So, HTTP methods = Operations
decorators and path decorators
@something
syntax in Python is called a "decorator"./
with an operation get
.Path decorators:
@app.post()
@app.put()
@app.delete()
@app.options()
@app.head()
@app.patch()
@app.trace()
Define the path operation function
/
.get
.@app.get("/")
).from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
This is a Python function.
It will be called by FastAPI whenever it receives a request to the URL "/
" using a GET
operation.
In this case, it is an async
function.