Hi Andrei, On 09/12/12 17:12, Andrei Shakirin wrote:
Hi,I need a suggestion regarding Rest best practices. ****************************************************************************** Use Case: There is CRUD java interface exposed as Rest service. Objects are identified using Long ID: @Path("/root") *public**interface*Service { @GET @Path("/{Id}") *public*ObjectTO read(@PathParam("Id") *final*Long id); @POST @Path("/") *public*Response create(*final*ObjectTO objectTO); @PUT @Path("/{Id}") *public*ObjectTO update(@PathParam("Id") *final*Long Id, *final*ObjectTO object); @DELETE @Path("/{Id}") *public*Response delete(@PathParam("Id") *final*Long Id); } Create operation returns Response object with link of created resource and HTTP 201 status code. **************************************************************************** Alternatives: Basically there are two ways to read object after creation: A)Using WebClient and URL returned with Response B)Extract object ID form URL returned with Response and use interface. ****************************************************************************** Alternative (A) seems to be more restful, but (B) allows to use central interface to access object that also has some benefits. Question: what is the recommended way to access objects in such situation? Should I decide between two ways or can I mix them?
I guess typically one would use either WebClient or the proxy style, though mixing both is possible.
Personally, I'd not consider it a question of the REST best practice, both approaches will produce the same HTTP request/response data...
As far as the 'purity' of the style is concerned, the more HTTP-centric style is the more RESTful it is often considered, so WebClient style will score better,
but as far as I'm concerned, I'd really choose the style which will make the code simpler/better/more flexible for a given case, and sometimes I'd probably choose either style with ease :-)
Thanks, Sergey
Cheers, Andrei.
