Best Practices for PUT in RESTful APIs

Discussion/Advice

How do you handle PUT requests?

Since I started learning about RESTful APIs, most tutorials include the Id in the route parameter. What happens if I pass the Id only in the body instead of the route? Would that go against RESTful principles?

Context: I considered this approach to simplify method parameters, as in the example below:

public TaskItem Update(TaskItemUpdateRequest request)
{
    TaskItem taskItem = GetById(request.Id);

    taskItem.Title = request.Title;
    taskItem.Description = request.Description;

    return taskItem;
}

public sealed record TaskItemUpdateRequest
{
    [Required]
    public required Guid Id { get; init; }

    [Required]
    [MaxLength(100)]
    public required string Title { get; init; }

    [Required]
    [MaxLength(500)]
    public required string Description { get; init; }
}

I did this to reduce the number of parameters. Otherwise, it would look like this:

public TaskItem Update(Guid id, TaskItemUpdateRequest request)
{
    TaskItem taskItem = GetById(id);

    taskItem.Title = request.Title;
    taskItem.Description = request.Description;

    return taskItem;
}

My question is about the correct way to implement PUT.

Another question: is PATCH necessary, or does PUT usually suffice? Also, do I need to check that all fields are filled to avoid saving null? I know that RESTful APIs recommend PATCH for partial updates, but I rarely see it used in practice.

Finally, regarding service responses: should add, update, and delete methods return anything, or nothing since they are actions and not queries?

Posted May 5, 2026, 5:27 PM UTC

913
Loading comments…