Skip to content

Should I use GET or PATCH for requesting info while also updating the resource [closed]

I am making a Blackjack service in Java using Spring, and i have methods for game moves like Hit, Stand, etc.

My question is, should I use GET or PATCH requests for this? I am asking for the current state of the game in json format, but when i use /hit it also changes the game by adding a card to the player hand. But again, I am still asking info back.

Which one should I use for this?

Thanks in advance.

Answer

GET methods should be both idempotent:

An HTTP method is idempotent if an identical request can be made once or several times in a row with the same effect while leaving the server in the same state. In other words, an idempotent method should not have any side-effects (except for keeping statistics). Implemented correctly, the GET, HEAD, PUT, and DELETE methods are idempotent

So calling them twice times consecutively should not change the behaviour of calling that method just once.

From what I see it seems that you add a new card each time that you call it, so you change the status after each call, not just after the first call. In this case I would prefer to use a PATCH.