0% found this document useful (0 votes)
191 views

What Is REST

RESTful Web Service The document discusses REST (REpresentational State Transfer), a architectural style for building web services. It defines REST as a set of guidelines for how clients access resources on a server using HTTP requests. Resources are uniquely identified by URIs and can be in various data formats like JSON or XML. The six constraints of REST are also outlined: uniform interface, stateless, cacheable, client-server separation, layered system, and optional code on demand. Advantages of REST include being lightweight, easier development, and direct access of resources via URIs. SOAP is also compared, with REST being better for simpler web APIs while SOAP is more suited for complex enterprise services.

Uploaded by

vinchooo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
191 views

What Is REST

RESTful Web Service The document discusses REST (REpresentational State Transfer), a architectural style for building web services. It defines REST as a set of guidelines for how clients access resources on a server using HTTP requests. Resources are uniquely identified by URIs and can be in various data formats like JSON or XML. The six constraints of REST are also outlined: uniform interface, stateless, cacheable, client-server separation, layered system, and optional code on demand. Advantages of REST include being lightweight, easier development, and direct access of resources via URIs. SOAP is also compared, with REST being better for simpler web APIs while SOAP is more suited for complex enterprise services.

Uploaded by

vinchooo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

RESTful Web Service

By Binu Chawla
OVERVIEW

What is REST ?
Resources and Representations
6 Constraints of REST architecture

When to use REST ?

Advantages of REST

Comparing SOAP and REST


What is REST ?
REST is an acronym for Representational State Transfer
RESTis an architectural style which was coined by Roy Fielding in 2000.
REST is not a protocol. REST is a set of guidelines which talk about how a
client should interact with a server.
REST + Web Services = RESTful web Services
REST is an approach that leverages the HTTP protocol.
Web services are services exposed to the internet for programmatic access.
They are online apis that developers can call from their code. Companies like
facebook and Twitter publish web services that let other developers call them
from their code, to read or access data or post data on a facebook wall.
RESTful web services work very similar to a web site.
HTTP Request
Client Server
HTTP Response in xml,
json, plain text or
html
RESOURCE
REST architecture treats every content as a resource. These resources can be text
files, html pages, images, videos or dynamic business data. REST Server simply
provides access to resources and REST client accesses and modifies the resources.
Ex- SSN can be a resource with attributes as Customer Id, SSN_Number, scores
etc. and with functionality as resgiterSSN, updateSSN etc.

Each resource is identified by a unique identifier or URIs/ global IDs. Just like
web pages have urls, rest apis have uri and addresses too.
Sample: <protocol>:/<service-endpoint>/<service-name>/<method-
name>/<resourceId>
http://162.144.126.209:8080/mortgage-v1.3.2/SSN/registerSsn.do
So in RESTful Web Services, Server is viewed as a set of resources and can
beaccessed usingUniform Resource Identifiers (URIs).
How does the server identify the request?
How does the client know which data format is being sent?
Metadata which is a part of the request and response header.
The http request header contains information like which http method
(GET,PUT,POST,DELETE), is used, the uri, the http version and query string parameters.
The http response header contains status code, content type which can be
application/json, or text/plain.
Every request and response contains meta data about the format of content being sent.
Different representation of same record or underlying data is being sent to different
client.
When you send any request or you get any response, you are actually sending
representations. REST uses various representations to represent a resource like html,
text, JSON, XML, pdf, and jpeg. So, we are transferring the representational state and
goes the name REST.

Client1 Server Client2


Application/json Application/xml
SSN Resource
{ <message>
FirstName : Shiv <FirstName>Shiv</FirstName>
LastName : Dayal <LastName>Dayal</LastName>
SSN: 123123123 <SSN>123123123</SSN>
} </message>
Six Constraints of REST architecture

1. Uniform Interface
2. Stateless
3. Cacheable
4. Client-Server
5. Layered System
6. Code on Demand (optional)
UNIFORM INTERFACES

Use Simple and Uniform interfaces


Use uniform methods of HTTP protocol and combine them with the resource
operation
To create a resource on the server, use POST.
To retrieve a resource, use GET.
To change the state of a resource or to update it, use PUT.
To remove or delete a resource, use DELETE.
registerSSN POST /ssn/CreditServices/<ssn-no>
getScore GET /ssn/CreditServices/<ssn-no>
updateSSN PUT /ssn/CreditServices/<ssn-no>
reportScore PUT /ssn/CreditServices/<ssn-no>
2. Stateless
Every request should be an independent request, which means that along with the data, also send the
state of the request(as part of the URI, query-string parameters, body, or headers) so that the server can
carry forward the same from that level to the next level. Then after the server does it's processing, the
appropriate state, or the piece(s) of state that matter, are communicated back to the client via headers,
status and response body.
3. Cacheable
As on the World Wide Web, clients can cache responses. Caching refers to storing server response in client
itself so that a client needs not to make server request for same resource again and again. A server
response should have information about how a caching is to be done so that a client caches response for a
period of time or never caches the server response. Well-managed caching partially or completely
eliminates some clientserver interactions, further improving scalability and performance.
4. Client Server
This separation of concerns means that, for example, clients are not concerned with data storage, which
remains internal to each server, so that the portability of client code is improved. Servers are not
concerned with the user interface or user state, so that servers can be simpler and more scalable. Servers
and clients may also be replaced and developed independently, as long as the interface is not altered.
5. Layered System
A client cannot tell whether it is connected directly to the end server, or to an intermediary server along
the way to improve system scalability.
6. Code on Demand(optional)
Advantages of REST
REST leverages the amazing features of web with above mentioned constraints.

Client can directly access a resource using its URI which is a direct advantage of
RESTful web service over SOAP web service, where client needs WSDL and XML message
transfer in form of envelope, headers etc.
For REST no middleware is required, only HTTP support is needed

REST is much more light weight and can be implemented using almost any tool leading
to lower bandwidth and shorter learning curve

Development with REST is easier and quicker than SOAP. Because, of this most of the
vendors are adopting RESTful Web Services e.g Flickr, Google etc. That is why REST is
often used in mobile applications,social networkingWeb sites,mashuptools,
andautomated business processes.
SOAP or REST

In general, when we are publishing an api to the outside world which is either
complex or likely to change, then SOAP is best. Other than that REST is a good
choice.
If the operation needs a guaranteed level of security and reliability, then
SOAP offers additional standards to ensure this type of operation.
Key to using SOAP based services is the WS - Standards. If there are a lot of
non functional requirements like security, transaction management etc. then
we can rely on the SOAP framework that provides all the standards for such
requirements.
REST is good for web services. However, SOAP is good for the enterprise
services that need high reliability, transaction mgmt. and high security.
SOAP v/s REST

The chariot is the overhead i.e SOAP


envelope,header. It wraps your data. Look
SOAP
at the complexity and added weight.
HTTP

REST REST rides directly on HTTP. Plain


and simple. In reality, this is all you
need to send data from Point A to
Point B and get response back.
No. SOAP REST

1. SOAP is a protocol REST is an architectural style


2. SOAP stands for Simple Object Access REST stands for Representational State
Protocol Transfer
3. SOAP cant use REST because its a RESTcan use SOAPweb services because
protocol it is a concept and can use any protocol
like HTTP, SOAP
4. Service definition is using WSDL Most restful web services have little to
none documentation about service
definition
5. De facto standard for exchanging RESTpermits differentdata format such
messages is XML. as Plain text, HTML, XML, JSON etc.
6. SOAPdefines standardsand rules to be REST does not define too much standards
strictly followed. like SOAP.
7. SOAPdefines its own security RESTful web servicesinherits security
measuresfrom the underlying transport.
8. SOAPrequires more bandwidthand RESTrequires less bandwidthand
resource than REST. resource than SOAP.
9. JAX-WSis the java API for SOAP web JAX-RSis the java API for RESTful web
services. services.

You might also like