DEV Community

Discussion on: Why you should use standard HTTP methods when designing REST APIs

Collapse
 
aleron75 profile image
Alessandro Ronchi

Nice article, I didn't focus on PATCH and idempotency so far.

Reading through the article a question arose: say we have an entity with an 'updated_at' attribute where we store the timestamp of the last update.

Since the 'updated_at' is changed every time we save the entity, saving through a PUT method would break the idempotency, is it correct?

In this case, should we consider to use a PATCH to update that kind of entities?

Thank you!

Collapse
 
suhas_chatekar profile image
Suhas Chatekar

It really depends on how your resources are represented.

One way to keep PUT still idempotent in that case would be to treat updated_at as a server generated value which the client has no control over, which is actually true in most cases. The from a client's perspective, the resource representation they send to the server is same every time and server can respond in an idempotent manner.

Collapse
 
aleron75 profile image
Alessandro Ronchi

Ok, that means that a GET shouldn't return the 'updated_at' attribute?
Sorry if I bother :)

Thread Thread
 
suhas_chatekar profile image
Suhas Chatekar

Why should it not?

Resource for PUT and GET can look different.

Thread Thread
 
aleron75 profile image
Alessandro Ronchi

Why should not

Just asking :)

Thank you for your clarification, it was very useful