Please ELI5 about POST / PUT / PATCH best practices

patarapolw

Pacharapol Withayasakpunt

Posted on March 11, 2020

Please ELI5 about POST / PUT / PATCH best practices

It might be

  • POST - Create NEW record
  • PUT - If the record exists, update else, create a new record
  • PATCH - update
  • GET - read
  • DELETE - delete

But, do you really ever use PUT requests?

Also, we have to consider which can have req.body. To my understandings, GET and DELETE shouldn't have BODY, so mine becomes

  • GET - Simple query, like ?id={id}
  • POST - Complex query that needs req.body / file upload
  • PUT - Create NEW record
  • PATCH - Update
  • DELETE - Delete

Another thing to consider, IDEMPOTENCY. Do I have care about it?

HTTP  Idempotency
GET     yes
POST    no
PUT     yes
PATCH   no*
OPTIONS yes
HEAD    yes
DELETE  yes
Enter fullscreen mode Exit fullscreen mode

Why can't we use POST for everything?

Also, don't forget that there are also HEAD and OPTIONS.

💖 💪 🙅 🚩
patarapolw
Pacharapol Withayasakpunt

Posted on March 11, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related