REST Web Services Characteristics Client

Download Report

Transcript REST Web Services Characteristics Client

Web Services using REST &
JAX-WS
Prepared By : Monika Darji
REST stands for REpresentational State Transfer
• The term Representational State Transfer was introduced
and defined in 2000 by Roy Fielding in his doctoral
dissertation
• It is an architectural style, not a toolkit.
• Resources are identified by uniform resource identifiers (URIs)
• Resources are manipulated through their
Representations.
• Messages are self-descriptive and stateless
• Example of a RESTful request:
POST /users HTTP/1.1
Host: myserver
Content-Type: application/xml
<?xml version="1.0"?>
<user>
<name>Robert</name>
</user>
Prepared By : Monika Darji
The basics
REST defines a set of architectural principles by which you
can design Web services that focus on a system's
resources, including how resource states are addressed
and transferred over HTTP by a wide range of clients
written in different languages. If measured by the
number of Web services that use it, REST has emerged
in the last few years alone as a predominant Web
service design model. In fact, REST has had such a
large impact on the Web that it has mostly displaced
SOAP- and WSDL-based interface design because it's a
considerably simpler style to use.
A concrete implementation of a REST Web service follows
four basic design principles:
1. Use HTTP methods explicitly.
2. Be stateless.
3. Expose directory structure-like URIs.
4. Transfer XML, JavaScript
Object Notation (JSON), or
Prepared By : Monika Darji
both.
Use HTTP methods explicitly.
REST asks developers to use HTTP methods explicitly and
in a way that's consistent with the protocol definition.
This basic REST design principle establishes a one-toone mapping between create, read, update, and delete
(CRUD) operations and HTTP methods. According to
this mapping:
* 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.
Prepared By : Monika Darji
Be stateless
•
A REST Web service application (or client) includes
within the HTTP headers and body of a request all of
the parameters, context, and data needed by the
server-side component to generate a response.
Statelessness in this sense improves Web service
performance and simplifies the design and
implementation of server-side components because
the absence of state on the server removes the need
to synchronize session data with an external
application.
Prepared By : Monika Darji
Expose directory structure-like URIs\
REST Web service URIs should be intuitive to the point where
they are easy to guess. Think of a URI as a kind of selfdocumenting interface that requires little, if any, explanation
or reference for a developer to understand what it points to
and to derive related resources. To this end, the structure of
a URI should be straightforward, predictable, and easily
understood.
Transfer XML, JSON, or both
The last set of constraints that goes into a RESTful Web
service design has to do with the format of the data that the
application and service exchange in the request/response
payload or in the HTTP body. This is where it really pays to
keep things simple, human-readable, and connected.
Prepared By : Monika Darji
REST Web Services Characteristics
• Client-Server: a pull-based interaction style: consuming
components pull representations.
• Stateless: 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.
• Cache: to improve network efficiency responses must be capable of
being labeled as cacheable or non-cacheable.
• Uniform interface: all resources are accessed with a generic
interface (e.g., HTTP GET, POST, PUT, DELETE).
• Named resources - the system is comprised of resources which are
named using a URL.
• Interconnected resource representations - the representations of
the resources are interconnected using URLs, thereby enabling a
client to progress from one state to another.
• Layered components - intermediaries, such as proxy servers,
cache servers, gateways, etc, can be inserted between clients and
resources to support performance,
security, etc.
Prepared By : Monika Darji
Examples
• REST can be found in many places on the public Web:
• The 'blogosphere' — the universe of weblogs — is
mostly REST-based, since it involves downloading XML
files (in RSS, or Atom format) that contain lists of links to
other resources;
• The Atom Publishing Protocol for publishing to blogs is
considered the canonical RESTful protocol;
• Amazon.com's S3 is their only truly REST offering;
• OpenStreetMap offers a REST interface
Prepared By : Monika Darji
RESTful Web Services versus SOAP Web Services
Message Format
Interface Definition
Transport
REST
XML
none
HTTP
SOAP
XML inside a SOAP Envelope
WSDL
HTTP, FTP, MIME, JMS, SMTP
Prepared By : Monika Darji
JAX-WS
• The Java API for XML Web Services (JAX-WS)
is a Java programming language API for
creating web services. It is part of the Java EE
platform from Sun Microsystems. It is part of the
Java Web Services Development Pack.
• The Reference Implementation of JAX-WS is
developed as an open source project and is part
of project GlassFish, an open source Java EE
application server.
Prepared By : Monika Darji
Service Oriented Architecture(SOA)
• Service-oriented architecture (SOA) is an evolution of
distributed computing based on the request/reply design
paradigm for synchronous and asynchronous
applications. An application's business logic or individual
functions are modularized and presented as services for
consumer/client applications. What's key to these
services is their loosely coupled nature; i.e., the service
interface is independent of the implementation.
Application developers or system integrators can build
applications by composing one or more services without
knowing the services' underlying implementations. For
example, a service can be implemented either in .Net or
J2EE, and the application consuming the service can be
on a different platform or language.
Prepared By : Monika Darji
Characteristics of SOA
* SOA services have self-describing interfaces in platformindependent XML documents. Web Services Description
Language (WSDL) is the standard used to describe the
services.
* SOA services communicate with messages formally
defined via XML Schema (also called XSD).
* SOA services are maintained in the enterprise by a registry
that acts as a directory listing. Applications can look up
the services in the registry and invoke the service.
Universal Description, Definition, and Integration (UDDI)
is the standard used for service registry.
* Each SOA service has a quality of service (QoS)
associated with it. Some of the key QoS elements are
security requirements, such as authentication and
authorization, reliable messaging, and policies regarding
who can invoke services.
Prepared By : Monika Darji
The ROLE OF WSDL in SOA
WSDL is the interface definition language (IDL) that defines
the interactions among SOA components. It provides a
standard language for describing how to communicate with
a component.
Following figure shows the role of WSDL for SOA..The
deployment takes place in Web Services Platform
subsystem.
The top-level class depicted in that subsystem is
ServiceDeployment. Each instance of ServiceDeployment
corresponds to a Web service that is deployed on this
platform.The ServiceDeployment contains both an
operation (taken from the WSDL interface description) and
a Java method. A Web service deployment defines a
relationship between a WSDL interface description and a
Java implementation of that description.
Prepared By : Monika Darji
Prepared By : Monika Darji
The ROLE OF SOAP in SOA
• The role of SOAP in SOA is to provide a
concrete implementation,or binding, for the
WSDL interfaces.
Prepared By : Monika Darji