java - Invoke RESTful webservice with parameter -


i have simple restful web service print "hello world !" i'm using netbeans , code looks like:

package resource;  import javax.ws.rs.core.context; import javax.ws.rs.core.uriinfo; import javax.ws.rs.consumes; import javax.ws.rs.put; import javax.ws.rs.path; import javax.ws.rs.get; import javax.ws.rs.produces;   @path("simple") public class simpleresource {      @context     private uriinfo context;      /** creates new instance of simpleresource */     public simpleresource() {     }      @get     @produces("application/xml")     public string getxml() {         //todo return proper representation object         return "<greeting>hello world !</greeting>";     }      @put     @consumes("application/xml")     public void putxml(string content) {     } } 

i call web service url : http://localhost:8080/webservice/resources/simple. now, want send parameter web service, print parameter after "hello world" message.

how can that?

thanks!

the 2 main ways of handling parameter in rest via parsing path , via extracting query part.

path parameters

these handle case — /foo/{fooid}{fooid} template replaced parameter want:

@get @produces("text/plain") @path("/foo/{fooid}") public string getfoo(@pathparam("fooid") string id) {     // ... } 

these great case can consider parameter describing resource.

query parameters

these handle case — /?foo=id — you'd doing traditional form processing:

@get @produces("text/plain") @path("/") public string getfoo(@queryparam("foo") string id) {     // ... } 

these great case consider parameter describing adjunct resource, , not resource itself. @formparam annotation extremely similar, except handling posted form instead of get-style parameters

other types of parameters

there other types of parameter handling supported jax-rs spec (matrix parameters, header parameters, cookie parameters) work in same way programmer, rarer or more specialized in use. reasonable place start exploring details jax-rs javadoc itself, has useful links.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -