Ojasa Mirai

Ojasa Mirai

FastAPI

Loading...

Learning Level

🟢 Beginner🔵 Advanced
🚀 What is FastAPI📚 Creating Your First API📚 Running the Server📚 HTTP Methods📚 API Endpoints📚 Request and Response📚 Documentation📚 Testing Basics
Fastapi/Api Basics/Api Endpoints

API Endpoints ⛳

API endpoints are the specific URLs where your API responds to requests. Each endpoint handles a specific operation.

What is an Endpoint?

An endpoint is a URL path combined with an HTTP method that performs a specific action:

from fastapi import FastAPI

app = FastAPI()

@app.get("/items")  # ← This is an endpoint
async def list_items():
    return {"items": []}

@app.post("/items")  # ← This is a different endpoint
async def create_item(item):
    return item

Endpoint Components

PartExamplePurpose
HTTP MethodGET, POST, PUTWhat operation
URL Path/users/123Where to access
Functionget_user()What to execute
ResponseJSON dataWhat to return

Creating Endpoints

# GET endpoint - retrieve data
@app.get("/users")
async def list_users():
    return {"users": []}

# POST endpoint - create data  
@app.post("/users")
async def create_user(user: dict):
    return {"id": 1, **user}

# GET endpoint with path parameter
@app.get("/users/{user_id}")
async def get_user(user_id: int):
    return {"id": user_id}

# DELETE endpoint - remove data
@app.delete("/users/{user_id}")
async def delete_user(user_id: int):
    return {"deleted": True}

Endpoint Paths

Paths define the URL structure:

# Simple path
@app.get("/items")

# Path with parameter
@app.get("/items/{item_id}")

# Path with multiple parameters
@app.get("/users/{user_id}/posts/{post_id}")

# Path with version
@app.get("/api/v1/products")

Testing Endpoints

Visit these URLs to test:

  • `http://localhost:8000/users` - GET endpoint
  • Use Postman or curl for POST/PUT/DELETE

🔑 Key Takeaways

  • ✅ Endpoints are URL + HTTP method combinations
  • ✅ Each endpoint performs one specific operation
  • ✅ Use descriptive path names
  • ✅ Different methods can share the same path
  • ✅ Interactive docs show all endpoints at /docs

Resources

Python Docs

Ojasa Mirai

Master AI-powered development skills through structured learning, real projects, and verified credentials. Whether you're upskilling your team or launching your career, we deliver the skills companies actually need.

Learn Deep • Build Real • Verify Skills • Launch Forward

Courses

PythonFastapiReactJSCloud

© 2026 Ojasa Mirai. All rights reserved.

TwitterGitHubLinkedIn