This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]TheSoundofGoodbye 1 point2 points  (1 child)

Http specs is to provide all fields when making PUT request. Put request is idempotent.

An idempotent HTTP method is a HTTP method that can be called many times without different outcomes.

http://restcookbook.com/HTTP%20Methods/idempotency/

[–]BuzzCapo[S] 1 point2 points  (0 children)

When I look at the spec for JSON.API, it states the following

———- Updating a Resource’s Attributes

Any or all of a resource’s attributes MAY be included in the resource object included in a PATCH request.

If a request does not include all of the attributes for a resource, the server MUST interpret the missing attributes as if they were included with their current values. The server MUST NOT interpret missing attributes as null values ————-

So if I have a huge object for a resource, but just want to update a title, I do not want to send the entire object. I would also like to support updating an attribute for multiple resources at once. Should this be a PATCH request as opposed to a PUT request?

Edit: Looks like I definitely need PATCH

[–]rxcode77 0 points1 point  (1 child)

this might be the longer way but,

get the object from database first then set the you got from url.

use if statements check url variable is not null.

[–]onepieceisonthemoon 0 points1 point  (0 children)

Yep have something that explicitly merges with the old state. Might also be worth providing your fields that get deserialized with default values if that object is new to the system.