Features

 Link : https://www.youtube.com/watch?v=H9Blu0kWdZE&list=PLK8U0kF0E_D6l19LhOGWhVZ3sQ6ujJKq_


1. Automatic docs :  

Fast API provides a swagger UI which shows what are the routes we have created and what are the 

-- Swagger UI
-- ReDoc

 Fast API : https://fastapi.tiangolo.com/

  

Core FastAPI Terminologies

 1. App Instance

from fastapi import FastAPI
app = FastAPI()

 

  • This is your main application object.
  • Everything (routes, configs) is attached to this.
  •  

    2. Path Operation (Route)

    @app.get("/users")

  • A path = URL (/users)
  • An operation = HTTP method (GET, POST, etc.)
  • Together: Path Operation
  • 👉 Meaning:

    “When a GET request comes to /users, run this function.”

     

    3. HTTP Methods

    • GET → Read data
    • POST → Create data
    • PUT → Update (full)
    • PATCH → Update (partial)
    • DELETE → Remove

     4. Path Parameters

    @app.get("/users/{user_id}")
    def get_user(user_id: int):

     

  • Dynamic values in the URL
  • Example: /users/10user_id = 10

  •  5. Query Parameters

     @app.get("/users")
    def get_users(limit: int = 10):

  • Comes after ? in URL
  • Example: /users?limit=5
  •  

     6. Request Body

    from pydantic import BaseModel

    class User(BaseModel):
        name: str
        age: int

    @app.post("/users")
    def create_user(user: User): 

  • Data sent in request (usually JSON)
  • Validated using Pydantic
  •  

    7. Pydantic Models

    • Used for:
      • Validation
      • Serialization
    • Ensures correct data types\

     

    8. Response Model

      @app.get("/users", response_model=User)

     

  • Defines what the API returns
  • Filters and validates output
  •  

    9. Dependency Injection

    from fastapi import Depends

    def get_db():
        return "DB Connection"

    @app.get("/")
    def read(db = Depends(get_db)):

     

  • Reusable logic (DB, auth, etc.)
  • Injected automatically
  •   

    10. Middleware

    • Runs before/after every request
    • Used for:
      • Logging
      • Authentication
      • CORS

     

    11. Status Codes

    from fastapi import status

    @app.get("/", status_code=status.HTTP_200_OK) 


    12. Exception Handling

    from fastapi import HTTPException

    raise HTTPException(status_code=404, detail="Not found")

     

    13. APIRouter

    from fastapi import APIRouter
    router = APIRouter()

     Used to split large apps into modules

     

    14. OpenAPI & Docs

    • Auto-generated docs:
      • /docs → Swagger UI
      • /redoc → ReDoc

     15. Async / Await

    @app.get("/")
    async def read():

    Enables high performance (non-blocking)

     

    🧠 Simple Mental Model

    Think of FastAPI like this:

    URL → Route → Function → Validate Input → Process → Return Response

     

      

    Comments