Design the Representation(s) Accepted from the Client
Design the Representation(s) to Be Served to the Client
Link This Resource to Existing Resources
What’s Supposed to Happen?
What Might Go Wrong?
Custom Places
Figure Out the Data Set
Split the Data Set into Resources
Name the Resources with URIs
Expose a Subset of the Uniform Interface
Design the Representation(s) Accepted from the Client
Design the Representation(s) Served to the Client
Link This Resource to Existing Resources
What’s Supposed to Happen?
What Might Go Wrong?
A Look Back at the Map Service
Chapter 7. A Service Implementation
A Social Bookmarking Web Service
Figuring Out the Data Set
Resource Design
REST in Rails
The User Controller
The Bookmarks Controller
The User Tags Controller
The Calendar Controller
The URI Controller
The Recent Bookmarks Controller
The Bundles Controller
The Leftovers
Remodeling the REST Way
Implementation: The routes.rb File
Design the Representation(s) Accepted from the Client
Design the Representation(s) Served to the Client
Connect Resources to Each Other
What’s Supposed to Happen?
What Might Go Wrong?
Controller Code
What Rails Doesn’t Do
Conditional GET
param[:id] for things that aren’t IDs
The ApplicationController
The UsersController
The BookmarksController
The TagsController
The Lesser Controllers
The CalendarController
The RecentController
The UrisController
Model Code
The User Model
The Bookmark Model
What Does the Client Need to Know?
Natural-Language Service Description
Description Through Standardization
Hypermedia Descriptions
Chapter 8. REST and ROA Best Practices
Resource-Oriented Basics
The Generic ROA Procedure
Addressability
Representations Should Be Addressable
State and Statelessness
Connectedness
The Uniform Interface
Safety and Idempotence
New Resources: PUT Versus POST
Overloading POST
This Stuff Matters
Why Addressability Matters
Why Statelessness Matters
Why the Uniform Interface Matters
Why Connectedness Matters
A terrifying example
Resource Design
Relationships Between Resources
Asynchronous Operations
Batch Operations
Transactions
When In Doubt, Make It a Resource
URI Design
Outgoing Representations
Incoming Representations
Service Versioning
Permanent URIs Versus Readable URIs
Standard Features of HTTP
Authentication and Authorization
Basic authentication
Digest authentication
WSSE username token
Compression
Conditional GET
Caching
Please cache
Thank you for not caching
Default caching rules
Look-Before-You-Leap Requests
Partial GET
Faking PUT and DELETE
The Trouble with Cookies
Why Should a User Trust the HTTP Client?
Applications with a Web Interface
Applications with No Web Interface
What Problem Does this Solve?
Chapter 9. The Building Blocks of Services
Representation Formats
XHTML
XHTML with Microformats
Atom
OpenSearch
SVG
Form-Encoded Key-Value Pairs
JSON
RDF and RDFa
Framework-Specific Serialization Formats
Ad Hoc XHTML
Other XML Standards and Ad Hoc Vocabularies
Encoding Issues
XML and HTTP: Battle of the encodings
The character encoding of a JSON document
Prepackaged Control Flows
General Rules
Database-Backed Control Flow
GET
PUT
POST for creating a new resource
POST for appending to a resource
DELETE
The Atom Publishing Protocol
Collections
Members
Service document
Category documents
Binary documents as APP members
Summary
GData
Querying collections
Data extensions
POST Once Exactly
Hypermedia Technologies
URI Templates
XHTML 4
XHTML 4 links
XHTML 4 forms
Shortcomings of XHTML 4
XHTML 5
WADL
Describing a del.icio.us resource
Describing an APP collection
Is WADL evil?
Chapter 10. The Resource-Oriented Architecture Versus Big Web Services
What Problems Are Big Web Services Trying to Solve?
SOAP
The Resource-Oriented Alternative
WSDL
The Resource-Oriented Alternative
UDDI
The Resource-Oriented Alternative
Security
The Resource-Oriented Alternative
Reliable Messaging
The Resource-Oriented Alternative
Transactions
The Resource-Oriented Alternative
BPEL, ESB, and SOA
Conclusion
Chapter 11. Ajax Applications as REST Clients
From AJAX to Ajax
The Ajax Architecture
A del.icio.us Example
The Advantages of Ajax
The Disadvantages of Ajax
REST Goes Better
Making the Request
Handling the Response
JSON
Don’t Bogart the Benefits of REST
Cross-Browser Issues and Ajax Libraries
Prototype
Dojo
Subverting the Browser Security Model
Request Proxying
JavaScript on Demand
Dynamically writing the script tag
Library support
Chapter 12. Frameworks for RESTful Services
Ruby on Rails
Routing
Resources, Controllers, and Views
Outgoing Representations
Incoming Representations
Web Applications as Web Services
The Rails/ROA Design Procedure
Restlet
Basic Concepts
Writing Restlet Clients
Writing Restlet Services
Resource and URI design
Request handling and representations
Compiling, running, and testing
Conclusion
Django
Create the Data Model
Define Resources and Give Them URIs
Implement Resources as Django Views
The bookmark list view
The bookmark detail view
Further directions
Conclusion
Appendix A. Some Resources for REST and Some RESTful Resources
Standards and Guides
HTTP and URI
RESTful Architectures
Hypermedia Formats
Frameworks for RESTful Development
Weblogs on REST
Services You Can Use
Service Directories
Read-Only Services
Read/Write Services
Appendix B. The HTTP Response Code Top 42
Three to Seven Status Codes: The Bare Minimum
1xx: Meta
100 (“Continue”)
101 (“Switching Protocols”)
2xx: Success
200 (“OK”)
201 (“Created”)
202 (“Accepted”)
203 (“Non-Authoritative Information”)
204 (“No Content”)
205 (“Reset Content”)
206 (“Partial Content”)
207 (“Multi-Status”)
3xx: Redirection
300 (“Multiple Choices”)
301 (“Moved Permanently”)
302 (“Found”)
303 (“See Other”)
304 (“Not Modified”)
305 (“Use Proxy”)
306: Unused
307 (“Temporary Redirect”)
4xx: Client-Side Error
400 (“Bad Request”)
401 (“Unauthorized”)
402 (“Payment Required”)
403 (“Forbidden”)
404 (“Not Found”)
405 (“Method Not Allowed”)
406 (“Not Acceptable”)
407 (“Proxy Authentication Required”)
408 (“Request Timeout”)
409 (“Conflict”)
410 (“Gone”)
411 (“Length Required”)
412 (“Precondition Failed”)
413 (“Request Entity Too Large”)
414 (“Request-URI Too Long”)
415 (“Unsupported Media Type”)
416 (“Requested Range Not Satisfiable”)
417 (“Expectation Failed”)
5xx: Server-Side Error
500 (“Internal Server Error”)
501 (“Not Implemented”)
502 (“Bad Gateway”)
503 (“Service Unavailable”)
504 (“Gateway Timeout”)
505 (“HTTP Version Not Supported”)
Appendix C. The HTTP Header Top Infinity
Standard Headers
Accept
Accept-Charset
Accept-Encoding
Accept-Language
Accept-Ranges
Age
Allow
Authorization
Cache-Control
Connection
Content-Encoding
Content-Language
Content-Length
Content-Location
Content-MD5
Content-Range
Content-Type
Date
ETag
Expect
Expires
From
Host
If-Match
If-Modified-Since
If-None-Match
If-Range
If-Unmodified-Since
Last-Modified
Location
Max-Forwards
Pragma
Proxy-Authenticate
Proxy-Authorization
Range
Referer
Retry-After
TE
Trailer
Transfer-Encoding
Upgrade
User-Agent
Vary
Via
Warning
WWW-Authenticate
Nonstandard Headers
Cookie
POE
POE-Links
Set-Cookie
Slug
X-HTTP-Method-Override
X-WSSE
Index
Nội dung
[...]... of Yahoo!’s webservices (http://developer.yahoo.com/) • Most other read-only webservices that don’t use SOAP • Static web sites • Many web applications, especially read-only ones like search engines ‡ More than you’d think The Google SOAP API for web search technically has a RESTful architecture So do many other read-only SOAP and XML-RPC services But these are bad architectures for web services, because... it easy to implement RESTfulweb services: Ruby on Rails, Restlet (for Java), and Django (for Python) We also have three appendixes we hope you find useful: Appendix A, Some Resources for REST and Some RESTful Resources The first part lists interesting standards, tutorials, and communities related to RESTfulwebservices The second part lists some existing, public RESTful webservices that you can... Amazon WebServices account (http://aws.amazon.com/) and customize the Ruby code with your Access Key ID Here’s a sample run of the program: $ ruby amazon-search.rb C1D4NQS41IMK2 "restful web services" "RESTful Web Services" by Leonard Richardson, Sam Ruby "Hacking with Ruby: Ruby and Rails for the Real World" by Mark Watson At its best, the programmable web works the same way as the human web When... Here we explain the Ajax architecture for web applications in terms of web services: an Ajax application is just a web service client that runs inside your web browser That makes this chapter an extension of Chapter 2 We show how to write clients for RESTful webservices using XMLHttpRequest and the standard JavaScript library Chapter 12, Frameworks for RESTfulServices In the final chapter we cover three... something goes wrong If you provide RESTful web services, you can spend your complexity on additional features, or on making multiple services interact Success in providing services also means being part of the Web instead of just “on” the Web: making your information available under the same rules that govern well-designed web sites The closer you are to the basic web protocols, the easier this is The... issues: how to design and implement RESTfulweb services, and clients for those services Our secondary focus is on theory: what it means to be RESTful, and why webservices should be more RESTful instead of less We don’t cover everything, but we try to hit today’s big topics, and because this is the first book of its kind, we return to the core issue—how to design a RESTful service—over and over again... program starts acting like a web browser It makes an HTTP request to a URI: in this case, something like http://xml.amazon.com/onca/xml3?KeywordSearch =restful +web+ services& mode=books&f=xml&type=lite&page=1 The web server at xml.amazon.com responds with an XML document This document, shown in Example 1-3, describes the search results, just like the HTML document you see in your web browser, but in a more... questions that webservices answer differently, I can group webservices by their answers to the questions In my studies I’ve identified three common web service architectures: RESTful resource-oriented, RPC-style, and REST-RPC hybrid I’ll cover each in turn RESTful, Resource-Oriented Architectures The main topic of this book is the web service architectures which can be considered RESTful: those which... Now, lots of architectures are technically RESTful, ‡ but I want to focus on the architectures that are best for webservices So when I talk about RESTfulweb services, I mean services that look like the Web I’m calling this kind of service resource-oriented In Chapter 3 I’ll introduce the basic concepts of resource-oriented REST, in the context of a real web service: Amazon’s Simple Storage Service... commonsense set of rules for designing RESTfulwebservices We also show you the view from the client side: how you can write programs to consume RESTfulservices Our examples include realworld RESTfulservices like Amazon’s Simple Storage Service (S3), the various incarnations of the Atom Publishing Protocol, and Google Maps We also take popular services that fall short of RESTfulness, like the del.icio.us . and implement RESTful web
services, and clients for those services. Our secondary focus is on theory: what it means
to be RESTful, and why web services should. you can im-
plement web services without implementing Big Web Services: that the Web should
be all the service you need. We believe the Web s basic technologies