liveBook · Manning

HTTP PUT method

As explained in The Design of Web APIs, Second Edition

PUT is the HTTP method for replacing a resource representation or creating it at a specified URI when permitted by the server.

PUT replaces or updates a resource and can create it at a client-specified URI when the server permits. It commonly represents an update or upsert in a REST API. section 4.3.1

Map common resource operations to PUT and its alternatives:

  • Update one element with PUT /elements/{element identifier}; use PATCH as an alternative for partial updates. section 4.3.6
  • Send the complete replacement representation with PUT; PATCH sends only modified properties. section 5.3.4
  • Prefer POST for server-generated identifiers; use PUT /products/{product reference} when the consumer supplies a suitable identifier. section 4.3.5

Replacing a product

A product update uses PUT /products/{productReference}. Its path identifies the resource, while the request body contains all properties needed to replace it. A successful update returns the new Product state; creation through the same URI returns 201 Created, distinguishing it from an update returning 200 OK. section 4.5.7 section 5.3.4

PUT is idempotent: repeating an identical request produces the same server effect, although idempotency alone does not prevent overwriting newer data. Complete replacements can also cost more than PATCH at scale. section 12.5.2 section 13.5.5

Figure 4.8 Refer to this mapping when in doubt about choosing an HTTP method for an action. CRUD stands for create, read, update, delete.
figure

Use the CRUD-to-HTTP mapping as a quick reference when choosing PUT, POST, PATCH, GET, or DELETE. section 4.3.1

How The Design of Web APIs, Second Edition covers it

How deep it goes
Explains replacement inputs, returned state, creation status, idempotency, PATCH trade-offs, and compatibility consequences.
Examples
Uses product catalog paths, complete product replacements, client-supplied identifiers, and transaction flags to contrast PUT with alternatives.
What it assumes
Assumes familiarity with REST resources and CRUD while teaching method selection, resource paths, replacement models, and status distinctions.
What you can do after
Build it from scratch by mapping resource operations, choosing PUT or PATCH, defining replacement inputs, and returning the updated state.
How it connects
Connects PUT with REST APIs, CRUD, POST, PATCH, resource identifiers, HTTP status codes, and idempotency.

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 The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.