Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

⚡ Chapter 31 – CRUD with FastAPI & MongoDB

In this chapter, we build a Student Management API using:

  • FastAPI for REST API endpoints
  • MongoDB Atlas for database storage
  • PyMongo for database queries

🔹 CRUD Mapping

  • CreatePOST /add
  • ReadGET /show
  • UpdatePOST /edit
  • DeleteGET /remove

🔹 API Endpoints

1. Show All Students

GET /show

Response:

{
  "data": [
    {"_id": "66abc123", "name": "Riya", "roll": 101, "marks": 85}
  ]
}

2. Add Student

POST /add?name=Riya&roll=101&marks=85

Response:

{"status": "66abc123"}

3. Edit Student

POST /edit?id=66abc123&name=Riya Singh

Response:

{"status": 1}

4. Delete Student

GET /remove?id=66abc123

Response:

{"status": 1}

🔹 Flow Diagram

Client ---> FastAPI Routes ---> PyMongo ---> MongoDB Atlas

🧠 Summary

  • FastAPI + MongoDB is powerful for backend APIs
  • CRUD maps to POST/GET endpoints
  • ObjectId must be converted to string for JSON responses