To define, it means if REST APIs make multiple requests and have the same effect as making a single request then that REST call is called idempotent.
In a similar way, there are idempotent HTTP methods, that if called multiple times does not produce different outcomes.
Which methods are idempotent and which not?
GET, PUT, DELETE, HEAD, OPTIONS and TRACE are idempotent.
POST is NOT idempotent.
Understand WHY !
1. HTTP – GET, HEAD, OPTIONS and TRACE
These methods are for retrieving data so invoking these methods will not write any data to the server, hence these methods are idempotent.
2. HTTP – PUT
Usually – not always – PUT APIs are used for performing update operations to a resource/record. Even if the PUT API is being called N number of times, the very first call will do the update but the next N-1 calls will not do any change as they will just overwrite what has already been written, hence PUT is idempotent too.
3. HTTP – DELETE
When you invoke N number of DELETE requests, the very first request will delete the resource/record but the other N-1 calls to this method will not do any further deletions for Obvious reasons as the record has already been deleted, hence DELETE is idempotent.
4. HTTP – POST
Usually – not everytime – POST APIs are used to create a new resource/record on server. And if you make N number of requests, then N number of resources/records will be created on the server, hence POST is not idempotent.
REST webservices Hello world tutorial
Next Follow this – tutorial and learn how to create REST webservices using Jersey(library).
Summary
In this article we learnt about idempotency in REST Http Status Codes, its meaning and its Understanding.
Hope you liked the article !