O'Reilly logo

RESTful Java Patterns and Best Practices by Bhakti Mehta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Safety and idempotence

The following section discusses in detail what are safe and idempotent methods.

Safe methods

Safe methods are methods that do not change the state on the server. For example, GET /v1/coffees/orders/1234 is a safe method.

Note

Safe methods can be cached. GET and HEAD are safe methods.

The PUT method is not safe as it will create or modify a resource on the server. The POST method is not safe for the same reasons. The DELETE method is not safe as it deletes a resource on the server.

Idempotent methods

An idempotent method is a method that will produce the same results irrespective of how many times it is called.

Note

The GET method is idempotent, as multiple calls to the GET resource will always return the same response.

The PUT method ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required