Wednesday, January 21, 2015

REST: When to Use GET, PUT, POST, DELETE in Non-CRUD Situations

In normal CRUD situations, the answer is obvious. In non-CRUD situations, this gets a bit more tricky.

I think the best way to approach this is based on the following quoted from REST Wikipedia page

"The PUT and DELETE methods are referred to as idempotent, meaning that the operation will produce the same result no matter how many times it is repeated. The GET method is a safe method (or nullipotent), meaning that calling it produces no side-effects. In other words, retrieving or accessing a record doesn't change it."
  • If the REST end-point has no side effect (e.g. search), use GET.
  • If it is idempotent, it is possible to use PUT or DELETE depending on the nature of the request
  • If not idempotent and has side effect, use POST

No comments:

Post a Comment