DEV Community

Vaibhavi Naik
Vaibhavi Naik

Posted on

Building My First API with FastAPI 🚀

After deciding to start learning FastAPI, I wanted to build something simple to understand how APIs actually work.

So today, I built my very first API using FastAPI.

Honestly, I expected backend development to feel complicated at first, but FastAPI made the setup surprisingly clean and beginner-friendly.

Setting Up FastAPI

First, I installed FastAPI and Uvicorn:

pip install fastapi uvicorn
Enter fullscreen mode Exit fullscreen mode

Then I created a file called main.py.

My First FastAPI Code

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def home():
    return {"message": "Hello FastAPI"}
Enter fullscreen mode Exit fullscreen mode

To run the server:

uvicorn main:app --reload
Enter fullscreen mode Exit fullscreen mode

After running this command, my API started working locally.

My First API Response

When I opened:

http://127.0.0.1:8000

I saw:


{
  "message": "Hello FastAPI"
}
Enter fullscreen mode Exit fullscreen mode

It felt surprisingly satisfying seeing my first backend response working.

The Coolest Part — Automatic Docs

One thing that immediately impressed me was the automatic API documentation.

FastAPI instantly generated:

/docs
/redoc

Swagger UI looked incredibly clean and made testing APIs much easier for beginners like me.

What I Learned Today

Here are a few things I understood while building this small API:

APIs return data instead of web pages
Routes define endpoints
FastAPI syntax feels very readable
Backend development feels less scary when starting small

Challenges I Faced

At first, I got confused with:

virtual environments
running uvicorn
understanding what app = FastAPI() actually does

But after experimenting a little, things slowly started making sense.

Next Step

Next, I want to learn:

GET vs POST requests
path parameters
request validation using Pydantic

I’ll keep documenting everything as I continue learning backend development with FastAPI 🚀

Top comments (0)