Skip to main content

Command Palette

Search for a command to run...

decorator in FAST API (Python)

Published
•1 min read•View as Markdown
W
Software Engineering student at FAST-NUCES building full-stack AI-powered systems end-to-end. I work across the full stack: Frontend: React.js & Next.js Backend: FastAPI & Express.js Mobile: React Native ML & NLP: scikit-learn, TF-IDF, Logistic Regression, Random Forest , XG-Boost , ANN. Deployment: Docker, Render, Vercel I don't just study ML concepts — I integrate them into real products and ship them. Currently going deeper into backend architecture, scalable API design, MLOps, and production deployment pipelines. Because writing code is just the beginning — shipping systems that work in the real world is the goal.

@app.get("/auth")

def authenticating():

return {"isLoggedIn": "saeed here"}

@app.get("/auth")?

This is called a decorator in Python.

A decorator is something that:

Takes a function and modifies or registers it in some way.

@app.get("/auth") means:

“Whenever someone sends a GET request to /auth, run the function written below.”

How does Python read this?

Python internally converts this:

@app.get("/auth")
def authenticating():
    return {"isLoggedIn": "saeed here"}

into something like this:

def authenticating():
    return {"isLoggedIn": "saeed here"}

app.get("/auth")(authenticating)

So basically:

  • app.get("/auth") returns a function

  • That function takes authenticating as argument

  • FastAPI stores it in a routing table

So FastAPI now knows:

Route: GET /auth  →  Call authenticating()