HTTP PUT sends a representation from the client to a resource URL, conventionally replacing the resource there. A replacement should include every property: omitted values may become null, and omitted nested data such as order tacos may be removed. section 7.1.3
Replacing an order
A Spring MVC handler can accept an order identifier in the URL and a complete TacoOrder in the request body. Setting the path identifier on the submitted object and saving it replaces the stored order. Use PATCH instead when changing only selected fields, such as an address. section 7.1.3
@PutMapping(path="/{orderId}", consumes="application/json")
public TacoOrder putOrder(
@PathVariable("orderId") Long orderId,
@RequestBody TacoOrder order) {
order.setId(orderId);
return repo.save(order);
}
The controller listing shows @PutMapping accepting JSON, binding the path and request body, assigning the resource identifier, and saving the complete representation. section 7.1.3
A client can also send a replacement with RestTemplate.put(). The method accepts a URI or string URL, serializes the supplied object, substitutes URL variables, and returns void. section 7.3.2
public void updateIngredient(Ingredient ingredient) {
rest.put("http://localhost:8080/ingredients/{id}",
ingredient, ingredient.getId());
}
This client example replaces an ingredient by sending an Ingredient object and using its identifier as the URL variable. section 7.3.2







