OVERVIEW Of RESTful Web Services
RESTful Web Services are defined as JSR 339. REST is an architectural style which is based on web-standards and the HTTP protocol. REST was first represented by Roy Fielding in the year 2000. And the set of architectural principles is called REpresentational State Transfer (REST)and RESTful architectures quickly became popular because they rely on a very robust transport protocol: HTTP .
RESTful web services reduce the client-server coupling, making it much easier to evolve a REST interface over time without breaking existing clients. RESTful web services are stateless and can make use of HTTP cache and proxy servers that helps in high load and scale much better. In addition, they are easy to build as no special toolkit or WSDL-like is required.
To design a RESTful web service, firstly need to know Hypertext Transfer Protocol (HTTP) and Uniform Resource Identifiers (URIs), and a few design principles. This means that each unique URL is a representation of some object. To interact with an object,use HTTP GET(to get its content), DELETE, POST (to create it), or PUT (to update the content).
Java API for RESTful web services (JAX-RS) defines a standard annotation-driven API that helps to build a RESTful web service in Java. The standard principles of REST, can be easily marked in a POJO via annotations.
What are RESTful Web Services ?
A RESTFul web services are based on HTTP methods and the idea of REST. A RESTFul web service usually defines the base URI for the services, the supported MIME-types (XML, text, JSON,user-defined, …) and the set of operations (POST, GET, PUT, DELETE) which are supported.
SOAP web services are meant to be able to use several transport protocols, HTTP being one of them. As a result, they only use a very small subset of its capabilities. On the other hand, RESTful web services are HTTP-centric and make the most of this very rich protocol.
In the REST architectural style, every piece of information is a resource, and these resources are addressed using Uniform Resource Identifiers (URIs), typically links on the Web.
The resources are acted on by using a set of simple, well-defined operations. The REST client-server architectural style is designed to exchange representations of these resources using a defined interface and protocol.
What are the key principles of RESTful Web Services ?
The key principles of RESTful Web Services are :
- Addressable resources
The key abstraction of information and data in REST is a resource, and all resource must be addressable via a URI. - A uniform, constrained interface
Use the small set of well-defined methods to manipulate the resources. - Representation-oriented
Interact with services using representations of that service .And have various formats of resource referenced by one URI. Various platforms need different formats. For example, browsers need HTML, JavaScript needs JSON , and a Java application may need XML. - Communicate statelessly
Applications which are Stateless are easier to scale.
Hypermedia As The Engine Of Application State (HATEOAS)
Data formats drive state transitions in an applications.
Differentiate between SOAP and RESTful web services ?
1. For Simple Object Access Protocol -SOAP acronym is used but forĀ REpresentational State Transfer -REST acronym is used.
2. SOAP is a messaging protocol which is based on XML while RESTĀ is an architectural style not a protocol.
3. SOAP has a standard specification while for REST there is none.
4. Messages of REST are self-contained while SOAP does not has such types of requirements.
5. SOAP is strongly typed, so for every part of implementation it has strict about the specification. While on the other hand, REST provides the idea and less restrictive about the implementation.
6. To expose the business logic SOAP uses service interface while to expose the business logic REST uses URI.
7. For SOAP web services JAX-WS is the java API but for RESTful web services JAX-RS is the java API.
8. SOAP requires more resource and bandwidth while REST requires less resource and bandwidth.
9. SOAP can defines it’s own security but from the underlying transport RESTful web services inherits security measures.
10. SOAP permits only XML data format but REST can permits various data format for example: HTML, XML, JSON etc.
11. SOAP is less suggested while REST suggested more in comparison to SOAP.