Sigfrid
Lundberg´s
Stuff

Idempotency and HTTP methods

Sigfrid Lundberg's Stuff 2010-03-13

Bookmark and Share

I've been working with the REST paradigm for years. Or that is what I've claimed. But really, what I've been delivering is really GETful web services. These are services delivering all services using GET-requests, which good if you're actually just delivering content. But REST the architecture behind the IT revolution. And central in the WWW is HTTP and there in the midst you'll find the HTTP methods.

Tab. 1. The methods defined in HTTP 1.1. Safe methods should not take any other action than retrieval. An idempotent method is one that has the same side effects if it is applied n times (n>0), as when it it is applied once.
Method safe idempotent
HEAD Yes Yes
GET Yes Yes
DELETE No Yes
PUT No Yes
POST No No
TRACE
OPTIONS

You can do a lot using REST and the set of methods defined for HTTP 1.1. I've put the method in Tab. 1. I'd like to dwell on the idempotency concept as applied to computing. I quote directly from Wikipedia:

In computer science, the term idempotent is used to describe methods or subroutine calls that can safely be called multiple times, as invoking the procedure a single time or multiple times has the same result; i.e., after any number of method calls all variables have the same value as they did after the first call.

This is a very useful property in many situations: It means that an operation can be repeated or retried as often as necessary without causing unintended effects. If the operation were non-idempotent, it would be necessary to keep track of whether it was already performed or not, which complicates many algorithms.

Let us make the gedanken experiment that the retrieval methods, GET and HEAD, in HTTP where not idempotent in exactly this sense. Lean back, close your eyes and meditate over the problem: Which sequence of pages would be necessary to retrieve today in order to get the original DNA structure.

To put it in another way: Idempotency is the feature of HTTP ensuring that you receive predictable content when you dereference an URI, rather than a my personalized version of, say, Watson & Crick.

Home

Subscribe to Stuff from Sigfrid LundbergSubscribe to my stuff

stuff by category || year

NB

My name is Sigfrid Lundberg. The stuff I publish here may, or may not, be of interest for anyone else.

On this site there is material on photography, music, literature and other stuff I enjoy in life. However, most of it is related to my profession as an Internet programmer and software developer within the area of digital libraries. I have been that at the Royal Danish Library, Copenhagen (Denmark) and, before that, Lund university library (Sweden).

The content here does not reflect the views of my employers. They are now all past employers, since I retired 1 May 2023.

Creative Commons License
This entry (Idempotency and HTTP methods) within Sigfrid Lundberg's Stuff, by Sigfrid Lundberg is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.