Introduction to Restful web services
Tags: java, webservices, rest, restful
Published: 2019-04-27 05:53:47

---
title: Introduction to Restful web services
published: true
description: 
tags: #java #webservices #rest #restful
---

<div dir="ltr" style="text-align: left;">In this post, we will see RESTful web service introduction.</div>
<div dir="ltr" style="text-align: left;">

<div dir="ltr" style="text-align: left;">

REST is an architectural style which was brought in by Roy Fielding in 2000 in his doctoral thesis. In the web services terms, REpresentational State Transfer (REST) is a stateless client-server architecture in which the web services are viewed as resources and can be identified by their URIs. Web service clients that want to use these resources access via globally defined set of remote methods that describe the action to be performed on the resource.

It consists of two components REST server which provides access to the resources and a REST client which accesses and modify the REST resources.

In the REST architecture style, clients and servers exchange representations of resources by using a standardized interface and protocol.REST isn't protocol specific, but when people talk about REST they usually mean REST over HTTP.
The response from server is considered as the representation of the resources. This representation can be generated from one resource or more number of resources.
<div style="clear: both; text-align: center;"><a style="margin-left: 1em; margin-right: 1em;" href="http://www.java2blog.com/wp-content/uploads/2013/04/RestfuArchitecture.jpg"><img src="https://4.bp.blogspot.com/-AG9PUSpz2Ss/UV1o7jnPRlI/AAAAAAAAA90/1qI9M2lZqnE/s1600/RestfuArchitecture.jpg" border="0" /></a></div>
REST allows that resources have different representations, e.g.xml, json etc. The rest client can ask for specific representation via the HTTP protocol.
<h3 style="text-align: left;">HTTP methods :</h3>
RESTful web services use HTTP protocol methods for the operations they perform.Methods are:
<ul style="text-align: left;">
 	<li><b>GET</b>:It defines a reading access of the resource without side-effects.This operation is idempotent i.e.they can be applied multiple times without changing the result</li>
 	<li><b>PUT</b> :  It is generally used for updating resouce.It must also be idempotent.</li>
 	<li><b>DELETE </b>: It removes the resources. The operations are idempotent i.e. they can get repeated without leading to different results.</li>
 	<li><b>POST</b> :It is used for creating a new resource. It is not idempotent.</li>
</ul>
<div>
<div style="text-align: justify;"><b>Idempotent</b> means result of multiple successful request will not change state of resource after initial application</div>
<div style="text-align: justify;">For example :</div>
<div style="text-align: justify;">Delete is idempotent method because when you first time use delete, it will delete the resource (initial application) but after that, all other request will have no result because resource is already deleted.</div>
<div style="text-align: justify;"></div>
<div style="text-align: justify;">Post is not idempotent method because when you use post to create resource , it will keep creating resource for each new request, so result of multiple successful request will not be same.</div>
</div>
<h2 style="text-align: left;">Features of RESTful web services:</h2>
<div style="text-align: left;">

<b>Resource identification through URI</b>:Resources are identified by their URIs (typically links on internet). So, a client can directly access a RESTful Web Services using the URIs of the resources (same as you put a website address in the browser’s address bar and get some representation as response).

</div>
<b>Uniform interface</b>: Resources are manipulated using a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE.

<b>Client-Server</b>: A clear separation concerns is the reason behind this constraint. Separating concerns between the Client and Server helps improve portability in the Client and Scalability of the server components.

<b>Stateless</b>: each request from client to server must contain all the information necessary to understand the request, and cannot take advantage of any stored context on the server.

<b>Cache</b>: to improve network efficiency responses must be capable of being labeled as cacheable or non-cacheable.

<b>Named resources</b> - the system is comprised of resources which are named using a URL.

<b>Interconnected resource representations</b> - the representations of the resources are interconnected using URLs, thereby enabling a client to progress from one state to another.

<b>Layered components</b> - intermediaries, such as proxy servers, cache servers, gateways, etc, can be inserted between clients and resources to support performance, security, etc.

<b>Self-descriptive messages</b>: Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others.

You can also check <a href="http://www.java2blog.com/2016/06/restful-web-services-interview-questions.html" target="_blank" rel="noopener noreferrer">Restful interview questions with answers for beginners and experienced</a>

<h2 style="text-align: left;">Web service Tutorial Content:</h2>
</div>
<ul>
 	<li dir="ltr" style="text-align: left;"><a href="http://java2blog.com/2013/03/web-service-tutorial.html">Web services in java</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2016/06/web-services-interview-questions.html">Web services interview questions</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://java2blog.com/2013/03/soap-web-service-tutorial.html">SOAP web service introduction</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://java2blog.com/2013/04/restful-web-service-tutorial.html">RESTful web service introduction</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2016/06/difference-between-soap-and-rest-web-services.html">Difference between SOAP and REST web services</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://java2blog.com/2013/03/soap-web-service-example-in-java-using.html">SOAP web service example in java using eclipse</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://java2blog.com/2013/03/jaxws-web-service-eclipse-tutorial.html">JAX-WS web service eclipse tutorial</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://java2blog.com/2013/03/jaxws-webservice-deployement-on-tomcat.html">JAX-WS web service deployment on tomcat</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://java2blog.com/2013/04/create-restful-web-servicesjax-rs-using.html">Create RESTful web service in java(JAX-RS) using jersey</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2015/10/restful-web-services-jaxrs-json-example.html">RESTful web service </a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2015/10/restful-web-services-jaxrs-json-example.html">JAJSONexample using jersey</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2016/03/restful-web-services-jaxrs-crud-example.html">RESTful web service </a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2016/03/restful-web-services-jaxrs-crud-example.html">JAXRS CRUD example using jersey</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2016/03/angularjs-restful-web-service-example.html">AngularJS RESTful web service </a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2016/03/angularjs-restful-web-service-example.html">JAXRS CRUD example using $http</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2015/10/restful-web-services-jax-rs-queryparam.html">RESTful Web Services (JAX-RS) @QueryParam Example</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2015/09/spring-restful-web-services-example.html">Spring Rest simple example</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2015/09/spring-restful-web-services-json-example.html">Spring Rest json example</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2016/08/spring-restful-web-services-xml-example.html">Spring Rest xml example</a></li>
 	<li dir="ltr" style="text-align: left;"><a href="http://www.java2blog.com/2016/04/spring-restful-web-services-crud-example.html">Spring Rest CRUD example</a></li>
</ul>
</div>