REST Web Services In Java Introduction
Rest api in java
Rest - Representational state transfer api
Web Services allows different applications to talk to each other and share data and services among themselves.For example a python guy can call a spring rest web service .
Web services is used to make the application platform and technology independent.
The following methods are commonly used in rest based architecture :-
first understand what is a resource ..Resource is anything that you can name and store like ..it could be something you are getting from the user ..or something that you are sending to the user ..anything that you can name and operate upon is called a resource .For example-Resource can be a URL in http
1.get - read only access to resource
Ex-whatever is coming from user ..it reads .
2.put-create a new resource
3.delete -deleted the resource
4.post-update existing resource
Steps for building simple java Restful web application
1. Down load jersey 2.x for rest web services in java and extract it and then Copy all the jar files in the Web container>Web-INF>lib folder and paste it there of your project .
It is very important ..otherwise our rest api won't work
2.Create a class and over it put a annotation @Path("/hello")
If on that url extention string you want this class to execute .
3.create methods you like and over it put @Get annotation and below it put @Produce(MediaType.text_XML) or some variation if you want your method to get called when you receive XML in this case ,or json or HTML in some other case .Your methods can return strings as a output to user .
to read "name" which has to be passed from the resource and followed by string sname to store it .
4.Go to web.XML ..and configure the names of the servlet . Look up jersey 2.x rest api web.xml configuration.
5.Run the application using a web server like tomcat.
6.Type the required path in the end of URL to test your methods and you will get your response .
REST stands for REpresentational State Transfer.
RESTful Web Services are fast because there is no strict specification like SOAP. It consumes less bandwidth and resource.
JAX-RS is the java api for restful Web services.