Request validation and error handling
There are several different methods of validation at our disposal. We’re going to look at two of them in this section: manual validation and data annotation and model binding validation.
Manual validation
This kind of validation is the simplest, as you are writing code inside the route handler (the body of the lambda expression within an endpoint) that validates the request and decides on the appropriate response.
We’ve already applied manual validation in some parts of the todo items API. For example, the PATCH method we created to update the due date on items first checks for the Todo item with the target ID. It could just assume that TodoItem exists in the list, but instead, we check first to see if it exists and then return a 404 NOT FOUND status code if this is the case:
app.MapPatch("/updateTodoItemDueDate/{id}",
(int id, DateTime newDueDate) =>
{
var index...