FastAPI Flashcards

⚑ 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.