In response to a POST, I will return the Location for the new resource.
However, I'm unable to find information on the preferred way to do this. I
could either use the Base URI builder:
@Path("/things")
public class ThingResource {
@POST()
public Response createThing(@FormParam("thingname") String thingName,
@Context UriInfo uriInfo) {
String id = createThing(thingName);
URI resourceUri =
uriInfo.getBaseUriBuilder().path(ThingResource.class).path(id).build();
return Response.created(resourceUri).build();
}
or the Absolute Path builder:
URI resourceUri = uriInfo.getAbsolutePathBuilder().path(id).build();
Is there a real-world difference between the two? I could maybe see that
the first option, using the class of the ThingResource, would be more
"canonical", but that's as far as I can see. Am I missing something more
important?
;ted
--
http://about.me/tedmyoung