Have you just created the ultimate RESTful interface for a revolutionary new web service and now want to document it? Good thing there's this excerpt from Subbu Allamaraju's RESTful Web Services Cookbook to clue you in on what it will take to get the job done.
Fully describe the following in human-readable documentation:
All resources and methods supported for each resource
Media types and representation formats for resources in requests and responses
Each link relation used, its business significance, HTTP method to be used, and resource that the link identifies
All fixed URIs that are not supplied via links
Query parameters used for all fixed URIs
URI templates and token substitution rules
Authentication and security credentials for accessing resources
For XML representations, if your clients and servers are capable of supporting XML schemas, use a schema language as a “convention” to describe the structure of XML documents used for representations in requests and responses. For other formats, use conventions to describe representations in prose.
No machine-readable description can replace human-readable documentation. Documenting your web service in human-readable format such as HTML is the most useful way to enable design-time discovery. When documenting your service, include all the information necessary to implement a client.
Lack of a standard description language is often cited as a limitation of REST. In reality, machine-readable description languages do not communicate the semantics necessary for client developers to write code. See, for examples, the documentation of web services by Yahoo! (http://developer.yahoo.com), Flickr (http://www.flickr.com/services/api/), Twitter (http://apiwiki.twitter.com/), and Google Data Protocol (http://code.google.com/apis/gdata/). All these services provide extensive human-readable documentation with examples.
Here is an example of what to include when documenting a RESTful web service. Consider the album example from the section called “How to Merge Resources” to support finding, creating, editing, duplicating, and merging albums. Tables 14.1, 14.2, and 14.3 illustrate how to document such a web service.
Table 14.1. Resources
This resource contains photo metadata and a link to a related binary photo media resource (such as a JPEG file).
This resource represents the uploaded photo. Submit
This resource contains zero or more photos. Use
This resource contains zero or more albums. Use
|Duplicate album controller|
This resource lets a client duplicate an album.
|Merge album controller|
This resource lets a client merge albums.
Table 14.2. URIs
Use this URI to get the 10 latest albums using
Use links with the relation
Use this URI template to search for albums.
Use this template to get a link to merge two albums into a new album. The server will delete the original albums after this operation. This operation cannot undone.
In this template, the tokens
Table 14.3. Link relation types
For the sake of brevity, the previous documentation excludes details of the XML documents and form parameters used.
Learn more about this topic from RESTful Web Services Cookbook.
While the REST design philosophy has captured the imagination of web and enterprise developers alike, using this approach to develop real web services is no picnic. This cookbook includes more than 100 recipes to help you take advantage of REST, HTTP, and the infrastructure of the Web. You'll learn ways to design RESTful web services for client and server applications that meet performance, scalability, reliability, and security goals, no matter what programming language and development framework you use.