I am new to RESTful services and their implementation on Spring 3. I would like your opinion on the best practices for returning type when a client creates a new resource in my server.
@RequestMapping(method = RequestMethod.POST,
value = "/organisation",
headers = "content-type=application/xml")
@ResponseStatus(HttpStatus.CREATED)
public ??? createOrganisation(@RequestBody String xml)
{
StreamSource source = new StreamSource(new StringReader(xml));
Organisation organisation = (Organisation) castorMarshaller.unmarshal(source);
// save
return ???;
}
A simple choice would be javax.ws.rs.core.Response, found in the Java EE’s own restful services package. It – simply – tells what the web server should answer to the HTTP request.
For instance:
Custom response headers and other exotic things like that are possible with that return type too, but I don’t think that would match with “best practices”.
uh, I missed that @ResponseStatus(HttpStatus.CREATED)… I guess my answer was not much of help.
Maybe this will help instead: How to return generated ID in RESTful POST?