Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/
Table of
Contents
Hide

Project Zero Developer’s Guide

Concepts and components
Basic concepts overview
Event processing
Writing Java handlers
Writing Groovy handlers
Firing events
Global Context
Global Context reference
Application directory layout
Virtualized directories
Assemble
PHP
Features and configuration
Configuration
Debugging
Dependencies
Packaging
Application classpath
Logging and tracing
RESTful resources
RESTful documentation
File serving
Response rendering
Validators and validation
HTTP error handling
Calling a remote resource
Using the Connection API
Sending an email using EmailConnection
Configuring destinations
Configuring protocols
Configuring connection handlers
Creating a connection handler
Creating a custom protocol transport
Simple logging connection handlers
Protocol reference
Client programming with Dojo
Runtime options
Deployment modifications
HTTP configuration
SSL configuration
Proxy configuration
Extending the CLI
Security considerations
Authentication
OpenID authentication
Extending security
Security tokens
CSRF prevention support
Extending token support
Leveraging TAI
User service
File based user service
LDAP user service
Extending user service
Security Utilities
Leveraging XOREncoder
Extensions
Atom support
RSS support
JSON support
XMLEncoder
REST to SOAP extension
URIUtils
Developer Web tools
Database setup tools
Configuring data access
Common query patterns
Advanced query patterns
Update patterns
Local database transactions
Extending data access
Configuration vendor differences
PHP data access
Resource model
Configuring ZRM
Resource model declaration
Programmatic model API
HTTP REST API
A ZRM mini tutorial
Active content filtering support
Default filters
Custom filters
Runtime management
Management commands
Zero socket opener
Other extension modules
Amazon E-commerce service
Flickr service
WeatherZero forecast service
Wikipedia service
Reference
Zero command line interface
JavaDoc - Public API
JavaDoc - Public SPI
JavaDoc - All Classes

 

RESTful documentation

You can create RESTful documentation with RESTdoc. All new Project Zero applications include the zero.docs.webtools component that enables the RESTdoc tool while the application is running. The RESTdoc tool generates HTML tables that describe the RESTful APIs exposed by your application and its dependencies. The following sections of this article describe how you can take advantage of RESTdoc to make life easier for programmers who want to communicate with your RESTful resources as part of AJAX-driven clients, server-side scripts, and more.

Adding RESTful comments to your code

All RESTful resources implemented using Project Zero's REST conventions are indexed and explained using HTML tables. To see the RESTful documentation for your application, you must first add RESTdoc comments to each of your RESTful resource methods. RESTdoc comments look exactly like JavaDoc comments, with a few new tags:

@success
Reports the HTTP status code that is returned on success, along with an explanation of what has happened as a result of the operation. An operation can define zero or more success codes, with 200 being the default.

@error
Reports the HTTP error code that is returned when the operation cannot run to completion, along with an explanation of possible causes. An operation can define zero or more errors.

@format
The data format used by an operation to send or receive payloads. For example, the data format of a GET operation refers to the data returned in the response body, while the data format of a POST operation refers to the content that is part of the request body. The value that comes after this tag can be anything, but MIME types such as text/html or application/json are best. These enable users to copy them directly into HTTP request headers.

@example
The value of this tag is free-form. You can use it to show a sample request or response body for the given operation. For example, if you are documenting an onRetrieve() method (HTTP GET) that returns a JSON object, you could provide a sample JSON object that shows all of the fields that can be expected in the response. Your sample data is displayed as-is when a user clicks on the Formats column of the REST table.

The following example shows a proper RESTdoc comment; the syntax is exactly the same whether your code is Java, Groovy, or PHP:

/**
 *
 * @success 200 Returns the profile for the user with the given ID.
 * @error 403 If the client is not authorized to read the user's profile data.
 * @error 404 If there is no profile for the user with the given ID.
 * @format application/json
 * @example
 * {
 *    "username": "dan", 
 *    "email": "dan@projectzero.org", 
 *    "locale": "en_US"
 * }
 *
 */
def onRetrieve()
{
    // etc.
}

Viewing the RESTful API documentation

Once you have added RESTdoc comments to your resource implementations, start your Project Zero application and visit http://localhost:8080/resources/docs in your favorite browser. You should see an index page that lists all of the RESTful resources in your application. Clicking on a name provides its documentation, as the following example shows:

Click to enlarge.

All of the information you put in your RESTdoc comments has been aggregated into an HTML table. Any RESTful methods that were not documented are left out of the table.

Using RESTdoc to explore resources

By default, RESTdoc generates REST tables that link to AJAX-driven test forms. You can click on any value in the URI column of the REST table to see a dialog, as shown in the following example, for setting up and submitting HTTP requests against the resource you're studying:

Click to enlarge.

Once you have configured the request data, you can send the request and view all of the response data (headers and body) in the same dialog, as shown in the following example:

Click to enlarge.

This feature is very helpful for programmers who want to reuse your RESTful resources and need help writing HTTP client code to communicate with them. The test forms can be used to send and resend requests without switching away from the documentation view, and any changes to the source comments during runtime are reflected in the REST tables the next time they are refreshed.

Configuring RESTdoc output

If RESTdoc is not creating the output you are expecting and you can not find the problem, you can get detailed information on what files it is parsing and what content it finds by setting your logging level to FINE in /config/logging.properties.

When deploying your Project Zero application in a production environment, you can replace the RESTdoc dynamic table generation with static files (because the APIs are not changing like during development). Remove the zero.docs.webtools dependency from your application's Ivy file and run the zero docs command; RESTdoc puts the documentation files in /public/docs and their content does not change unless you re-run the command.

r10 - 05 Dec 2007 - 19:39:51 - paynel
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site