A fully functional Notes REST API built with FastAPI — part of my #60DaysOfPython challenge on Day 12.
- Pydantic models for request validation (
NoteCreate,NoteUpdate) - Full CRUD operations via REST API
- Path parameters and query parameters
- Partial updates with optional fields
- HTTP error handling with proper status codes
- In-memory storage with auto-incremented IDs
- Bonus: importance filter and keyword search
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Welcome message |
| GET | /notes |
Get all notes (with total count) |
| GET | /notes?keyword=xyz |
Search notes by title keyword |
| GET | /notes/important |
Get only important notes |
| GET | /notes/{note_id} |
Get a single note by ID |
| POST | /notes |
Create a new note |
| PUT | /notes/{note_id} |
Update a note (partial update) |
| DELETE | /notes/{note_id} |
Delete a note by ID |
NoteCreate — used for POST requests:
class NoteCreate(BaseModel):
title: str
content: str
is_important: bool = FalseNoteUpdate — used for PUT requests (all fields optional):
class NoteUpdate(BaseModel):
title: Optional[str] = None
content: Optional[str] = None
is_important: Optional[bool] = None- Python 3
- FastAPI
- Pydantic
- Uvicorn
- Clone the repository:
git clone https://github.com/studyhaxer/python-day12-fastapi-notes-api.git- Navigate to the project folder:
cd python-day12-fastapi-notes-api- Create and activate virtual environment:
python -m venv venv
venv\Scripts\activate- Install dependencies:
pip install "fastapi[standard]"- Run the app:
uvicorn main:app --reload- Open in browser:
- API:
http://127.0.0.1:8000 - Swagger Docs:
http://127.0.0.1:8000/docs
- Create 3 notes via POST
- Fetch all notes — confirm total is 3
- Fetch one note by ID
- Search notes by keyword
- Filter important notes
- Update a note partially
- Delete a note
- Try invalid ID — confirm 404 response
- How to define and use Pydantic models in FastAPI
- Difference between
NoteCreateandNoteUpdatemodels - How optional fields enable partial updates
- Why route order matters in FastAPI
- How query parameters work alongside path parameters
- Proper HTTP status codes for each operation
studyhaxer — Day 12 of #60DaysOfPython | FastAPI Notes API 🚀