liveBook · Manning

HTTP PUT method

As explained in Building Web APIs with ASP.NET Core

PUT is an HTTP request method for replacing a resource or creating it when it does not exist.

PUT is an HTTP method for creating a targeted resource when it does not exist or replacing it when it does. Its defining property is idempotence: repeating the same request should produce the same server outcome. section 5.5.1 section 1.1.4

Choose PUT only when repeated identical updates have the same effect. If every update deliberately changes server state—for example, refreshing a LastModifiedDate—use a nonidempotent method such as POST instead. section 5.5.1

Use the method whose semantics match the operation:

  • Use PUT to replace a known resource or create it at the requested target when repetition remains idempotent. section 5.5.1
  • Use POST to create a resource or perform a nonstandardized state change when repeated requests can produce different effects. section 5.5.1 section 1.1.4
  • Distinguish PUT from PATCH: REST assigns PUT to replacement, while PATCH updates an existing resource. section 1.1.4

Board-game update decision

An API that updates a board game's name and year also records the current time in LastModifiedDate. Because each execution changes that timestamp, the operation is nonidempotent and is implemented with POST rather than PUT. section 5.5.1

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines replacement, creation, and idempotence, then stops short of implementing a PUT endpoint.
Examples
Uses a board-game update with a LastModifiedDate timestamp to demonstrate why POST can replace PUT.
What it assumes
Assumes familiarity with HTTP requests and introduces REST method responsibilities through direct comparisons.
What you can do after
Evaluate whether an update is idempotent and select PUT or POST accordingly.
How it connects
Connects PUT with REST, HTTP methods, idempotence, POST, PATCH, and resource replacement.

Also explained in

Compare how 8 books explain HTTP PUT method →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.