liveBook · Manning

HTTP PUT method

As explained in Learn Go with Pocket-Sized Projects

PUT is an HTTP request method conventionally used to create or fully replace the representation of a resource at a specified URI.

PUT updates an existing resource identified by a URI. An endpoint combines the PUT method with a resource path such as /games/{game_id}; repeated calls should leave an idempotent resource state. section 8.2

Implement a PUT endpoint by making the resource and request contract explicit:

  • Use a path identifying the resource, such as /games/{game_id}. section 8.2
  • Decode the JSON request body into a typed request structure. section 8.2.3
  • Send the complete resource representation when appropriate; send only fields needed for a focused update when the API permits it. section 8.2.3

Submitting a game guess

A Gordle service uses PUT /games/{game_id} to change a game's status. The client sends curl -v -X PUT "http://localhost:8080/games/123456" -d '{"guess":"hello"}'. The handler decodes the guess from the JSON body and updates the identified game. section 8.2.3

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines update semantics, idempotence, paths, JSON bodies, and decoding errors, but does not detail storage internals.
Examples
Demonstrates PUT /games/123456 with a {"guess":"hello"} body and a Go handler decoding GuessRequest.
What it assumes
Assumes familiarity with HTTP endpoints and JSON decoding while reinforcing resource paths and request contracts.
What you can do after
Apply it via Go's HTTP APIs to define, call, and validate an update endpoint carrying JSON.
How it connects
Connects PUT with HTTP methods, REST, resource paths, JSON, request bodies, handlers, and idempotence.

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 Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.