users@jersey.java.net

[Jersey] For Response.created(), prefer Base URI or Absolute Path?

From: Ted M. Young [_at_jitterted] <tedyoung_at_gmail.com>
Date: Tue, 30 Apr 2013 15:14:23 -0700

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