───✱*.。:。✱*.:。✧*.。✰*.:。✧*.。:。*.。✱ ───
Why FastAPI?
- Modern & fast
- Comparable to Node.js and Go
- Easy to use
- Automatic docs generation
- Python 3.6+ type hints for better developer experience
- Ideal for quickly building RESTful APIs
What is Uvicorn?
- Uvicorn is a blazingly fast (🦀) ASGI (asynchronous server gateway interface) server that powers FastAPI application
- Uvicorn possesses concurrency, designed to be fast and lightweight to support async web apps
- We will be using Uvicorn as a server in which we will run FastAPI apps
What is Pydantic?
- Pydantic allows us to create models that represent the structure of our data.
- The models will automatically validate and parse the data coming into your application, making sure it fits the required types and constaints.
- Very useful when a certain data type or structure is needed (such as JSON)
Basic API Endpoint
- The structure of a FastAPI application is quite simple, with the key element being routes, which are functions that have decorators indicating what type of requests is being sent to the application:
from fastapi import FastAPI()
app = FastAPI()
@app.get("/")
async def read_root():
return { "hello": "world" }Running Your App
- To run your app locally, you can run
uvicorn main:app --reloadin the workspace directorymain→ file name without.pyapp→ FastAPI instance--reload→ auto-restart on code changes
Generated Documentation
- FastAPI generates documentation automatically for your application
- The documentation types can be accessible when the FastAPI app is running
- Swagger UI →
/docs - Redoc →
/redoc
- Swagger UI →
───✱*.。:。✱*.:。✧*.。✰*.:。✧*.。:。*.。✱ ───