Update with Null values

91 views
Skip to first unread message

Alex Ugol

unread,
Feb 16, 2015, 6:45:42 AM2/16/15
to api-...@googlegroups.com
Hi,

I'm designing a RESTfull API, and would like to know your opinion regarding null values while updating a resource.

When getting null values in Update requests, should I update the requested properties to null (assuming they are not mandatory), or consider them as not passed for update? 

Example:
{
   "name":"alex",
   "info": null
}

Update the info property to null? Or ignore the update on that property? What is the convention / better approach?

Thanks,
Alex

Jørn Wildt

unread,
Feb 16, 2015, 7:03:34 AM2/16/15
to api-...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "API Craft" group.
To unsubscribe from this group and stop receiving emails from it, send an email to api-craft+...@googlegroups.com.
Visit this group at http://groups.google.com/group/api-craft.
For more options, visit https://groups.google.com/d/optout.

Andrew Braae

unread,
Feb 16, 2015, 2:00:31 PM2/16/15
to api-...@googlegroups.com
If by "update request" you mean a PATCH operation with a media type of application/merge-patch+json, as per https://tools.ietf.org/html/rfc7386, then the answer is that the value for "info" is removed.

PATCH /target HTTP/1.1
Host: example.org
Content-Type: application/merge-patch+json

Chris Mullins

unread,
Feb 18, 2015, 3:38:07 PM2/18/15
to api-...@googlegroups.com
I would expect that to be read as "The new value of info is null". 

The Principal of Least Surprise applies here as and doing what devs intuitively expect is certainly a good thing. 

Cheers,
Chris
Reply all
Reply to author
Forward
0 new messages