skip to Main Content

I’m building a RESTful API, and I’m confused about which HTTP method to use when updating a record. Should I use POST, PUT, or PATCH in my request? In my scenario, I want to update specific fields of a resource, not the entire resource. For example, I might want to update only a user record’s name or email field. What’s the recommended approach for this kind of operation according to RESTful best practices? Are there specific use cases for each method, and what are the pros and cons of each?

what is the best approach while updating a record?
and what are the pros and cons of using POST, PUT, or PATCH?

I appreciate any guidance on this matter! Thank you.

2

Answers


  1. I believe the standard approach would be to use PATCH here.

    Login or Signup to reply.
  2. PATCH is used to apply partial updates to a resource, meaning that only the fields that need to be changed are sent in the request body. For example if you have a resource with name, age, gender and if you only want to update name and only pass the name in the body you should use PATCH.

    PUT is used to replace the entire resource with a new representation. If you pass everything in the body then you should use PUT

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search