web services - How to do multiple of operations in Java Webservice -


i using java/rest/jersey webservice.

i have users service,

..../rest/users/get/username ..../rest/users/get/all 

... want other things, sports

.../rest/sports/get/sport .../rest/sports/play.. 

i know can map users rest1 servlet , sports rest2 servlet, in fact have now. but, there way both things (users , sports & ...) in 1 servlet? don't fact have rest1,rest2,rest3,rest4...

..../rest/users/get/username ..../rest/sports/play ... 

you can define service endpoints patterns.

should review endpoints, 'cause /rest/users/get/username seems make no sence me. if want something, use method. no need have in url / endpoint. examples in code:

@path("/{parameter: rest1|rest2|rest.n}/users") public class users {      // [rest1|rest2|...]/users/{userid}/username     @get     @path("/{userid}/username")     @produces({mediatype.application_json,...})     public response getuserusername(@pathparam("userid") string userid) {         // ... return username specific user     }      // [rest1|rest2|...]/users/usernames     @get     @path("/usernames")     @produces({mediatype.application_json,...})     public response getusernames() {         // ... return usernames     } 

if want have in single resource class:

@path("/{parameter: rest1|rest2|rest.n}") public class rest {      @get     @path("/users")     @produces({mediatype.application_json,...})     public response getusers() {         // ...     }      @get     @path("/sports")     @produces({mediatype.application_json,...})     public response getsports() {         // ...     } 

... pls don't ;)


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -