Should I use PATCH or PUT in my REST API?

前端 未结 6 1098
予麋鹿
予麋鹿 2020-11-30 16:33

I want to design my rest endpoint with the appropriate method for the following scenario.

There is a group. Each group has a status. The group can be activated or in

6条回答
  •  误落风尘
    2020-11-30 17:00

    The PATCH method is the correct choice here as you're updating an existing resource - the group ID. PUT should only be used if you're replacing a resource in its entirety.

    Further information on partial resource modification is available in RFC 5789. Specifically, the PUT method is described as follows:

    Several applications extending the Hypertext Transfer Protocol (HTTP) require a feature to do partial resource modification. The existing HTTP PUT method only allows a complete replacement of a document. This proposal adds a new HTTP method, PATCH, to modify an existing HTTP resource.

提交回复
热议问题