users@jersey.java.net

Re: [Jersey] RESTful API with optional XML elements/JSON properties

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Fri, 06 Mar 2009 14:52:13 -0500

On Mar 6, 2009, at 2:30 PM, Jaka JanĨar wrote:
>
> I want to develop a RESTful API, which would differentiate between
> no occurance of an XML element/undefined JSON property and a xsi:nil
> element/null property.
>
> Why? Take for example a PUT request to /users/15:
>
> <user>
> <comapnyId xsi:nil="true"/>
> </user>
>
> This would remove the user from a company, while leaving everything
> else unchanged. Similarly:
>
> <user>
> <password>foo</password>
> </user>
>
> would change the user's password, while leaving the company unchanged.
>
Consider using PATCH or POST instead. PUT is intended to replace the
representation at the request URI with the one you supply rather than
patching it as a diff. The latest spec for PATCH is here:

http://www.ietf.org/internet-drafts/draft-dusseault-http-patch-13.txt

Marc.


> I would also use this in the opposite direction, with GET requests,
> when requesting different "views" (subsets) of a resource: no
> <company> element would mean that the company was simply not
> retrieved and the full representation must be fetched, while a nil
> element would mean that there is no company set for the user.
>
> Secondly, how would I ago about implementing this?
>
> In Javascript there's a difference between no object property ("if
> (prop in obj)" or "if (obj.prop === undefined)") and a null property
> ("if (obj.prop === null"). Similarly in PHP and others.
>
> In Java I guess I would need another field, for example xxxDefined
> for each field. Or are there any smarter alternatives?
>
> Has anyone done anything similar yet?
>
> Regards,
> Jaka
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>