Professional Documents
Culture Documents
By J. H. Wang
Nov. 28, 2011
Outline
Overview
RESTful Web services
Web service
An interface described in a machine-processable
format (WSDL, or Web Services Description
Language)
Other systems interact with the Web service using
SOAP messages, typically conveyed using
XML/HTTP and other Web-related standards
SOAP: Simple Object Access Protocol
Arbitrary
SOAP Message
Web APIs
Moving from SOAP based services to REST
based communications
REST: Representational State Transfer
Do not require XML, SOAP, WSDL
Representation of concepts in
WSDL 1.1 and 2.0 documents
Criticisms
Too complex, not open source
A custom interface requires a custom
client for every service
Concerns about performance due to XML
and SOAP/HTTP in enveloping and
transport
Client-server
Clients initiate requests
Servers process requests and return appropriate
responses
Requests and responses are built around the transfer
of representations of resources
Constraints
Client-server
Stateless
No client context is stored on the server between requests
The server can be stateful
Cacheable
Clients can cache responses
Layered system
Clients cannot tell whether its connected directly to the end
server, or an intermediary
Uniform interface
Key Goals
One-to-one mapping
For example,
Before
GET /adduser?name=Robert HTTP/1.1
After
POST /users HTTP/1.1
Host: myserver
Content-Type: application/xml
<?xml version="1.0"?>
<user>
<name>Robert</name>
</user>
Another example
Before
GET /updateuser?name=Robert&newname=Bob HTTP/1.1
After
PUT /users/Robert HTTP/1.1
Host: myserver
Content-Type: application/xml
<?xml version="1.0"?>
<user>
<name>Bob</name>
</user>
Be Stateless
For scalability, clients are required to send
complete, independent requests
include all data needed to be fulfilled so that
the components in the intermediary servers
may forward, route, and load-balance without
any state being held locally in between
requests
Guidelines
Hide the server-side scripting technology file extensions (.jsp,
.php, .asp), if any, so you can port to something else without
changing the URIs
Keep everything lowercase
Substitute spaces with hyphens or underscores (one or the other)
Avoid query strings as much as you can
Instead of using the 404 Not Found code if the request URI is for
a partial path, always provide a default page or resource as a
response.
References
http://en.wikipedia.org/wiki/Web_service
RESTful Web services: the basics, by Alex
Rodriguez, IBM developerWorks, available
at:
http://www.ibm.com/developerworks/webserv
ices/library/ws-restful/
.