FastAPI

What is FastAPI?

FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.6+ based on standard Python type hints.

OIM3600

Companies using FastAPI

OIM3600

FastAPI - Routing

  • What is routing in FastAPI?
  • How does routing work in FastAPI?
    • Routes are defined using decorators like @app.get(), @app.post(), etc.
    • Decorators associate an HTTP method and URL path with a function.
    • When a client sends a request, FastAPI matches it to the corresponding function and executes it.
OIM3600

FastAPI - Other Key Features

  • Automatic Data Validation
    • Checks data types for you, using simple Python hints.
  • Interactive API Documentation
    • Creates interactive docs for testing endpoints easily (Swagger UI, ReDoc).
  • High Performance
    • Built for fast speed using powerful tools (Starlette, Pydantic).
  • Dependency Injection
    • Helps connect things like databases with less code.
  • Asynchronous Support
    • Supports async to run many tasks at once.
OIM3600

Get Started with FastAPI

  1. Installation
    > python -m pip install fastapi uvicorn Jinja2 python-multipart  # Windows users
    > python3 -m pip install fastapi uvicorn Jinja2 python-multipart  # macOS/Linux users
    
  2. Creating our first FastAPI application
    1. Create a project/folder, hellofastapi. Open this folder in VS Code.
    2. Create a file named main.py
    3. Copy code from "First Steps" in the FastAPI Tutorial
    4. Run the app using uvicorn main:app --reload in terminal
    5. Or add the following to main.py (for debugging):
      if __name__ == "__main__":
          uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
      
OIM3600

FastAPI Resources

OIM3600

Front-End / Back-End / Full-Stack Web Development

OIM3600