β‘ FastAPI Flashcards
π What is FastAPI?
FastAPI is a modern, high-performance web framework for building APIs with Python 3.7+ based on standard Python type hints.
π Why is FastAPI fast?
It is built on top of Starlette and Pydantic and uses asynchronous programming to achieve high performance.
π What does Pydantic do?
Pydantic handles data validation and parsing using Python type annotations.
π¦ How to install FastAPI?
Run
pip install fastapi[all]
to install FastAPI with optional dependencies like Uvicorn.π What is Uvicorn?
Uvicorn is an ASGI server used to run FastAPI apps asynchronously.
π§ͺ How to test a FastAPI app?
You can use FastAPI’s TestClient with pytest or unittest for endpoint testing.
π§Ύ What is OpenAPI support?
FastAPI auto-generates OpenAPI docs and a Swagger UI interface based on your route declarations.
π How to add authentication?
Use OAuth2, JWT tokens, or FastAPI’s Security utilities for authentication and authorization.
π Where to define routes?
Define routes using the
@app.get()
, @app.post()
, etc., decorators within Python files.π Can FastAPI serve static files?
Yes, by using Starletteβs StaticFiles class to mount directories like
/static
.