开发者

HTTP PUT - enclosed entity be stored under the supplied Request-URI, does that mean Delete and Add?

开发者 https://www.devze.com 2023-03-30 18:24 出处:网络
According to the spec: The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing

According to the spec:

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server.

So if I have to implement a RESTFul service to change the age of a Person:

id: 100, name: John Doe, description: Tall, age: 40

to age 60, should my PUT request contain

id: 100, name: John Doe, description: Tall, age: 60

or just

age: 60

Should the server be expected to merge and update just what changed or completely delete and r开发者_开发问答e-add the resource?


PUT replaces. If you want to just modify part of the resource, use PATCH (or assign separate URIs to the individual aspects of the resource)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号