Rest & Restful Web Services
Rest & Restful Web Services
SERVICES
In a Nutshell
A protocol.
A standard.
A replacement for SOAP.
REST
REQUEST
GET /news/ HTTP/1.1
Host: example.org
Accept-Encoding: compress, gzip
User-Agent: Python-httplib2
http://localhost:9999/restapi/books
GET – get all books
POST – add a new book
http://localhost:9999/restapi/books/{id}
GET – get the book whose id is provided
POST – update the book whose id is provided
DELETE – delete the book whose id is provided
REST Characteristics
• Methods: Use only HTTP methods such as GET, PUT, POST, DELETE, HEAD
• Representation
Protocol (The constraints and the principles)
Client-Server
Stateless
Cacheable
Layered
HTTP Methods
RESTful web services are web services which are REST based.
Stateless & cacheable.
Uses URI & HTTP methods.
Frequently used with SOA projects.
Quiet light, extensible and simple services.
The reason behind the popularity of REST is that the
applications we use are browser-based nowadays and top it all,
REST is built on HTTP.
Main idea: Providing the communication between client and
server over HTTP protocol rather than other complex
architectures like SOAP and RPC etc.
RESTful Web Services
Seperation of concerns.
Client and server are independent from eachother.
Client doesn’t know anything about the resource which is kept in the server.
Server responds as long as the right requests come in.
Goal: Platform independency and to improve scalability.
Stateless
Scalability
Simplicity
Modifiability
Useability
Portability
Reliability
Benefits
Network Performance Other Benefits
Efficiency Simplicity
Scalability Evolvability
Reuseability
User Perceived
Performance Visibility
Extensibility
Configuration
Customizability
Benefits ctd.
HTTP is efficient because of all those caches, your request may not have to reach
all the way back to the origin server.
Scalability comes from many areas. The use of layers allows you to distribute traffic
among a large set of origin servers based on method, URI or content-type, or any
other visible control data or meta-data in the request headers.
Caching also helps scalability as it reduces the actual number of requests that hit
the origin server.
Statelessness allows requests to be routed through different gateways and proxies,
thus avoiding introducing bottlenecks, allowing more intermediaries to be added as
needed. [Scalability]
Will REST Replace Other Technologies ?
If you mean the load of the server, REST has a bit better performance because
it bears minimal overhead on top of HTTP. Usually SOAP brings with it a stack
of different (generated) handlers and parsers. Anyway, the performance
difference itself is not that big, but RESTful service is more easy to scale up
since you don't have any server side sessions.
If you mean the performance of the network (i.e. bandwidth), REST has much
better performance. Basically, it's just HTTP. No overhead. So, if your service
runs on top of HTTP anyway, you can't get much leaner than REST.
Furthermore if you encode your representations in JSON (as opposed to XML),
you'll save many more bytes.
In short, I would say 'yes', you'll be more performant with REST. Also, it (in my
opinion) will make your interface easier to consume for your clients. So, not
only your server becomes leaner but the client too.
Performance is broad topic!-2
*However, couple of things to consider!
RESTful interfaces tend to be a bit more "chatty", so depending on your
domain and how you design your resources, you may end up doing more HTTP
requests.
SOAP has a very wide tool support. For example, consultants love it because
they can use tools to define the interface and generate the WSDL file and
developers love it because they can use another set of tools to generate all
the networking code from that WSDL file. Moreover, XML as representation
has schemas and validators, which in some cases may be a key issue. (JSON
and REST do have similar stuff coming but the tool support is far behind)
Complements or Competitors ?