java - JAX-RS Root and subresource -


im in processes of developing rest api using jax-rs , have come across , issue sub resources. able access resource directly sub-resource. example /products return me list of products. /user/1/products return products associated user id 1 only.

below way have found it. else have neater/better ways of doing it?

thanks reading.

ben.

@path("/users") public class userresource {      @get     public list<user> getusers() {         /* return users */     }      @get     @path("{id}")     public user getuser(@pathparam("id") int id) {         /* return single user */     }      @path("{id}/products/")     public productresource getproductresource(@pathparam("id") int id) {         return new productresource(id);     } }  @path("/products") public class productresource {      private int id;      public productresource() {     }      public productresource(int id) {         this.id = id;     }      @get     public list<product> getproducts() {         if(id != 0) {             /* return products specific user */         } else {             /* return products */         }     } } 


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -