I'm stuck on Test the PATCH endpoint" endpoint after successfully sending a POST request.
I'm getting an error http 405 method not found.
ToDoAPI:
###Patch request | Debug
PATCH {{TodoApi_HostAddress}}/todoitems/1
Content-Type: application/json
{
"name": "run errands"
}
Program.cs:
app.MapPatch("/todoitems/{id}", async (int id, TodoPatchDto inputTodo, TodoDb db) =>
{
var todo = await db.Todos.FindAsync(id);
if (todo is null)
return Results.NotFound();
if (inputTodo.Name is not null)
todo.Name = inputTodo.Name;
if (inputTodo.IsComplete is not null)
todo.IsComplete = inputTodo.IsComplete.Value;
await db.SaveChangesAsync();
return Results.NoContent();
});
I've tried these solutions:
Moved the
###so it sits before thePOST/PATCHline (marking the start of a new request), not between the request line and itsContent-Typeheader.Fixed it → generic "error sending request" (cert/port issue).
Fixed cert/port → 400, body wasn't attaching (same
###issue, different spot).Fixed that → generic error again, port mismatch (7031 vs 7071).
Sent PATCH → 404. No PATCH route existed, only GET/POST/PUT/DELETE.
Used Endpoints Explorer "Generate request" for PATCH.
Still 404. Last step: confirm
MapPatchis actually inProgram.csand the app was rebuilt after adding it — unconfirmed, left open there.
Any suggestions?