REST Introduction

advertisement
REST Introduction
吴海生 博克软件(杭州)有限公司
Agenda
•
•
•
•
•
•
•
REST Concept
REST Constrains
REST Data Elements
REST V.S. SOAP
REST V.S. SOA
How to be RESTful
Q&A
REST Concept
REST is
• Representational State Transfer between Resource
• A style of software architecture
• A Virtual state-machine
A network of web pages (a virtual state-machine),
where the user progresses through an application by selecting links (state
transitions), resulting in the next page (representing the next state of the application)
being transferred to the user and rendered for their use.
REST Constraints
• Client-Server
• Separation principle
• Components Independent
• Stateless
• Session state on the client
• Visibility, reliability and scalability
• Trade off (network performance, etc.)
• Cacheable
• A response can be cacheable
• Efficiency but reduce reliability
• Layered system
• System scalability
• Code on demand (optional)
• Extension after deployment
• Uniform Interface
• Simple
REST Data Elements
• Resources and Resource Identifiers
• Uniform Interface (GET, PUT, POST, DELETE)
• Resource Oriented
• Simple and simple is beautiful
HTTP
Method
CRUD
Desc.
POST
CREATE
Create
-
GET
RETRIEVE
Retrieve
Safe,Idempotent,Cacheable
PUT
UPDATE
Update
Idempotent
DELETE
DELETE
Delete
Idempotent
REST Data Elements
Representations
• HTML / XML / images / sounds / …
REST V.S. SOAP
SOAP
• Simple Object Access Protocol
• RPC protocol that go through firewalls
• Communication protocol between applications
• A format for sending messages
REST V.S. SOAP
REST
•“The Web is the universe of globally accessible information”
• Resource oriented
• User-driven interactions via forms
• Few operations (generic interface) on many resources
• URI: Consistent naming mechanism for resources
• Focus on scalability and performance of large scale distributed
hypermedia systems
SOAP
•“The Web is the universal transport for messages”
• Activity/Service oriented
• Orchestrated reliable event flows
• Many operations (service interface) on few resources
• Lack of standard naming mechanism
• Focus on design of integrated (distributed) applications
REST V.S. SOA
Two of most common styles of use of Web Services
•Service-oriented architecture
• “Message oriented” (SOAP)
• Contract provided by WSDL
•REST
• Focus on interacting with stateful resources, rather than
messages or operations.
REST V.S. SOA
SOA principles
•Standardized Service Contracts
•Service Loose Coupling
•Service Abstraction
•Service Reusability
•Service Autonomy
•Service Statelessness
•Service Discoverability
•Service Composability
REST principles
•Unique identifiability of the
resources through URIs
•Uniform interface to access the
resources
•Navigability of the resource
representations through
hypermedia
•Statelessness
Correlation
• REST is an architectural style that inherently helps to attain some
of the basic SOA principles.
REST Introduction
Q&A
REST Introduction
Thank you!
Download