Lesson Complete!

Update an Expense

What you learned

  • The difference between PUT (full replacement) and PATCH (partial update) and why PATCH is more practical for user-facing APIs
  • How to create a separate Pydantic model with all optional fields for partial updates
  • How model_dump(exclude_unset=True) tracks which fields the client actually sent versus which were left out
  • How to merge only the provided fields into an existing expense using dict.update()

Next up

Your API now supports all four CRUD operations, but every time the server restarts, all data is lost. In the next lesson, you will add file-based persistence so that expenses survive server restarts.