How is the best approach to define a RESTFul web service API for fetch specific relation of a JPA entity?
Example:
If a have a resource User with an atribute Roles (1-N relations)
I would like some times to call my resource getUserByName (I do not want to bring the relations because performance) and getUserByNameWithRoles (here I want the relation for evict double network trip)
How is the best way to get this with java rest?
@Path("/user")
class UserResource{
@GET
@Path("/{name}")
public Response getUserByName(@PathParam("name") String name){
// hibernate query: select u from User u where u.name = :name
}
@GET
// How I map this URL?
@Path("/{name}")
public Response getUserByNameWithRoles(@PathParam("name") String name){
// hibernate query: select u from User u inner join fetch u.roles where u.name = :name
}
}
1) Have 2 methods?
2) Use some "expand" trick, with a @QueryParam (does exist any framework for this or it is by hand)
How your guys are solving this?