How to implement REST web-services? -
i trying learn java web-service using rest architecture. far have created class don't know how consume service. here's code:
import javax.ws.rs.get; import javax.ws.rs.produces; import javax.ws.rs.path; @path("/sericecreation") public class sericecreation { @get @produces("text/plain") public string display(){ return "hello"; } }
now, want call display method. can me understand how can achieved?
in simplified point of view, rest services bound http calls, in example @get
annotation tells method accessed making http get
call.
you can point browser url generated service , should see "hello" response. url http://<server>:<port>/<appcontext>/<rest-servlet-mapping>/sericecreation
where:
<server>
server name. typicallylocalhost
<port>
default server port number. if usin jboss 8080<appcontext>
typically name of applicaction (war file)<rest-servlet-mapping>
resteasy or jersey frameworks servlet path/sericecreation
comes@path
annotation used
in class.
another way intereact services using rest client one.
and of course, if want create java client can use apache http client library
, java.net.*
package or others. remember, rest services accessed making http calls.
i recommend read 2 tutorials general idea of rest architecture.
this great tutorial shows lot of examples using jersey or resteasy in order implement java rest services.
Comments
Post a Comment