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 to access a resource by a common interface, we use 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’s purpose is to provide read-only access to a resource.
    • POST − It’s purpose is to create a new resource.
    • DELETE − It’s purpose is to remove an existing resource.
    • PUT − It’s purpose is to update an existing resource or create a new resource.
  • A web service is a collection of open protocols and standards. It helps to exchange 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 design allows us 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 nothing but 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 –
    • 404: RESOURCE NOT FOUND
    • 200: SUCCESS
    • 201: CREATED
    • 401: UNAUTHORIZED
    • 500: SERVER ERROR

Annotaions –

  1. @Path
    • To specify the relative path of class and methods. By scanning the Path annotation value, one can get the URI of a web service.
  2. @GET, @PUT, @POST, @DELETE, @HEAD
    • To specify the HTTP request type for a method.
  3. @PRODUCES, @CONSUMES
    • To specify the request and response types.
  4. @PathParam
    • 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.
  5. @PathVariable
    • For data passed in the URI (e.g. RESTful web services).
  6. @RequestParam
    • To extract the data found in query parameters.
  7. QueryParam
    • To access key/value pairs in the query string of the URL (the part after the ?).
SOAPREST
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.
Scroll to Top