We currently have the following code, which is prototypical for a POST /
GET combination. POST is implemented by the root resource, and must
return a location header pointing to the created sub resource. Then, a
client can use that URI to GET a sub resource, implemented by a second
class:
@Path("myroot") public class RootResource {
@POST public post() {
...create in database and request id from it...
URI location =
UriBuilder.fromResource(SubResource.class).build(...id from
database...);
return Response.created(location).build();
}
@Path("{id}") public SubResource getSubResource() {
return new SubResource();
}
}
@Path("{id}") public class SubResource {
@GET public String get() {
return ... ;
}
}
That works pretty well, but it is not smart that @Path is needed at
both, the getSubResource() method AND the SubResource class.
I wonder if we can get rid of one of those, as the information provided
by both actually is the same.
Thanks!
Markus