java - RESTful: how to dynamically extend an API path's (or available resources)? -


i've had nice 'ride' restful technology. using hello.java resource this:

@path("/hello") public class hello {     ... /* get/put/post */ } 

with can access resource path http://my.host/res/hello . want 'ride' restful harder. having 1 resource path bit boring.

problem

i have dynamically created resources this:

  • http://my.host/res/hello
  • http://my.host/res/hello/1
  • http://my.host/res/hello/2
  • ...
  • http://my.host/res/hello/999

it doesn't make sense create .java resource every @path("/hello/1") ... @path("/hello/999"). right? list of sub-resources bigger or dynamically change in time. solution that?

thanks.

you can use @path annotation on methods inside resource class.

@path("/hello") public class hello {     ... /* get/put/post */      @get     @path("{id}")     public string mymethod(@pathparam("id") string id) {...} } 

the paths concatenated match /hello/13. {id} placeholder actual value entered, can retrieved @pathparam. in previous uri, string id have value 13.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -