What is Web Services, Web Services Introduction
What is Web Services ? Over the internet, you might have seen different kinds of definitions for Web services. My definition will almost resembles them Web Services, the name it self indicates that its a service which is available over the Web, that’s it. As an example you can consider Java4s.com, When ever you hit the URL in the web browser it will gives you some output in HTML format, you can also consider this as a Web service. With web services, we can communicate different applications on different platforms, i mean a java application in Windows platform can easily communicate with the application developed using .net/php in Linux operation system.
Understanding SOAP and REST
Web Services are mainly of 2 types, SOAP [Simple Object Access Protocol] and REST [Representational state transfer] based services. We have different type of specifications to implement SOAP and REST services. I believe so far you might be in confusion with these kind keywords like, JAX-RS, JAX-WS, RESTful, SOAP, Apache Axis2, Apache CXF bla bla… Let me try to bring you out of them.
- JAX-RS provides the implementation of RESTful web services, JAX-RS is a specification for RESTful Web Services with Java and it is given by Sun. Since it is a specification, other frameworks can be written to implement these specifications, and that includes Jersey from Oracle, Resteasy from Jboss, CXF from Apache bla bla.
- JAX-WS, Apache Axis2 provides the implementation for SOAP
- Apache CXF provides implementation for SOAP and RESTful services both.
What ever the data/response we will get from the server is known as Resource [remember this point], Each resource can be accessed by its URI’s. We can get the resource from RESTful service in different formats like, HTML,XML,JSON,TEXT,PDF and in the Image formats as well, but in real time we mainly we will prefer JSON. REST guidelines always talks about stateless communication between client and the Server. Stateless means, every single request from client to server will be considered as a fresh request. Because of this reason REST always prefers to choose HTTP as it a stateless protocol.
- GET - Retrieve Data
- POST- Create/Insert Data
- PUT- Update Data
- DELETE- Delete Data
Generally we will prefer RESTful Services in these scenarios…
- If clients require caching, means if you have limited bandwidth
- If you want every thing to be stateless [ I have already explained about stateless ]
But SOAP gives the output only in XML format. Hope you are good now by the way we are going to use Jersey to implement JAX-RS specifications.