Restful Web Services

  • REST stands for REpresentational State Transfer.
  • In REST architecture, clients and servers exchange representations of resources by using a standardized interface and protocol.
  • In REST Architecture everything is a resource and a resource is accessed by a common interface using HTTP standard methods. 
  • The REST Server provides access to resources and the REST client accesses and modifies the resources.
  • Each resource is identified by URIs/ global IDs.
  • REST uses many different representations to represent a resource like text, JSON, XML. JSON is the most popular one.
  • The four HTTP methods most commonly used in REST based architecture –
    • GET − It provides read-only access to a resource.
    • POST − It is used to create a new resource.
    • DELETE − It is used to remove an existing resource.
    • PUT − It is used to update an existing resource or create a new resource.
  • A web service is defined as a collection of open protocols and standards. It is used for exchanging data between applications or systems. REST Architecture based web services are known as RESTful web services.
Restful Web Services –

RESTful Web Services is a lightweight, maintainable, and scalable service that is built on the REST architecture. It exposes API from your application in a secure, uniform, stateless manner to the calling client. Using the Restful service, the calling client can perform predefined operations. The REST architecture is designed in order to use the stateless protocol of HTTP.  

  • It is language and platform-independent.
  • It should not keep a client state on the server. This restriction is called Statelessness. The client is responsible to pass its context to the server and then the server can store this context to process the client’s further request.
  • It can be configured for internalization. Internationalization is the process of designing web applications or services in such a way that it can provide support for various countries, various languages automatically without making the changes in the application. It is also known as I18N because the word internationalization has a total of 18 characters starting from I to N.
  • It basically defines a URI, Uniform Resource Identifier. In other words, a service that provides resource representation such as JSON and a set of HTTP Methods.
  • To create a URI, Use Plural Noun, Avoid using spaces,  Use lowercase letters, Maintain Backward Compatibility, and Use HTTP Verb.
  • HTTP defines the following standard status code –
    • 200: SUCCESS
    • 201: CREATED
    • 500: SERVER ERROR
Annotaions –
  • @Path – It is used to specify the relative path of class and methods. By scanning the Path annotation value, one can get the URI of a web service.
  • @GET, @PUT, @POST, @DELETE, @HEAD – It is used to specify the HTTP request type for a method.
  • @PRODUCES, @CONSUMES – It is used to specify the request and response types.
  • @PathParam – It is used to bind the method parameter to path value by parsing it. In other words, to map the variable URI path fragments into your method call.
  • @PathVariable – It is used for data passed in the URI (e.g. RESTful web services).
  • @RequestParam – It is used to extract the data found in query parameters.
  • QueryParam – It is used to access key/value pairs in the query string of the URL (the part after the ?).
It is a protocol.It is an architectural style.
Server and client applications are tightly coupled and bind with the WSDL contract.There is no contract in REST web services and clients.
The request and response type can be XML only.Request and response types can be XML, JSON, text, etc.
JAX-WS is the Java API for SOAP web services.JAX-RS is the Java API for REST web services.