HTTP Methods and Their Guarantees

HTTP methods for APIs: what GET, POST, PUT, PATCH and DELETE promise, and which are safe to repeat.

  • 10 cards
  • 7 questions
  • About 18 min
  • Beginner to Intermediate
Share

A client whose request times out has one question: may I send it again? The answer is written in the first word of the request. The method tells the server what the call intends, and it tells every cache, proxy, browser and retry library what they may do with it without asking anyone.

The topic starts with an API call seen as an HTTP request, then gives the five common methods their meanings and sorts them by two promises, safe and idempotent. Two comparisons follow, GET against POST and PUT against PATCH, and an example sends three writes twice to watch the promises hold or fail. The QUERY method covers searches too large for a URL, and a gotcha shows what happens when a GET changes data.

Which status code to send back is the next topic's subject, and retrying payments safely with idempotency keys comes later in this subject.

By the end you can choose the method for an operation, say which methods are safe and which idempotent, predict what sending a write twice does, and spot a GET that should not be one.

Contents

10 cardsnot started