Managing a nested resource in Jax-RS/Jersey that sometimes should behave as a non-nested resource <p>I am developing simple APIs with Jax-RS Jersey. Let's say I am considering the domain of items sold by stores in some country.</p> <p>My design includes these two calls :</p> <ul> <li>/webapi/items</li> <li>/webapi/store/1/items</li> </ul> <p>Both of them should return a list of items, the first one should return all the items sold in that country, the second one should return only the items sold by store number 1.</p> <p>I have of course two resources, an ItemResource which handles all the requests regarding items, and a StoreResource which handles all requests regarding stores.</p> <pre><code>@Path("items") class ItemResource { @GET public List&lt;Item&gt; getAllItems(){ } </code></pre> <p>.</p> <pre><code>@Path("stores") class StoreResource @GET @Path("/{storeId}/items") public List&lt;Item&gt; getItemsSoldByStore(@PathParam("storeId") long storeId) { } </code></pre> <p>What I would like to do is to pass the second request to the ItemResource, in order to avoid coupling between <code>StoreResource</code> and model class <code>Item</code> or database interfaces (like DAOs) specifically created to manage Items. I know I can consider ItemResource like a sub-resource, or a nested resource of StoreResource, but the point is that this is not always true, since sometimes I would like to call ItemResource without passing a store id, to get all items (this is the case of the first request <a href="http://foo.com/webapi/items" rel="nofollow">http://foo.com/webapi/items</a> ). I'd like to keep the <code>@Path("items")</code> annotation on the <code>ItemResource</code> so it handles every request to /items endpoint. </p> <p>What is the correct design in this situation? Thanks for any help.</p>