views:

185

answers:

4

I would like to thoroughly document an API service (with at least HTML). This service follows resource-oriented RESTful best practices. Are there any tools that can assist in compiling and and maintaining this documentation, or do I have to build it all from scratch?

A: 

What I do I generate both the service interface and the documentation from an XML file, by going through an XSLT transformation. The XML is something like:

<type name="User">
 <field name="Name" type="string">
 <description>The User Name</description>
 </field>
</type>
<resource name="Users" type="User">
  <verb name="Add" method="POST"/>
  <verb name="List" method="GET"/>
</resource>

From this I run one XSLT that generates the HTML documentation and one that generates the service entry point code (in this case PHP, but is irelevant). The XML format and both XSLTs are craeted by me from scratch, but the gist of this is that there is one single definition for both the spec and the code: the XML file. In fact there is a 3rd XSLT that is used to generate the REST service client code (C# in my case), from the same XML. I'm quite happy with this approach, but I reckon is a very specific solution, not some industry agreed practice.

I have asked a similar question Should I describe REST services in a machine readable format.

Remus Rusanu
+2  A: 

All you need to do is document your media types. To quote Roy from here

A REST API should spend almost all of its descriptive effort in defining the media type(s) used for representing resources and driving application state, or in defining extended relation names and/or hypertext-enabled mark-up for existing standard media types. Any effort spent describing what methods to use on what URIs of interest should be entirely defined within the scope of the processing rules for a media type (and, in most cases, already defined by existing media types). [Failure here implies that out-of-band information is driving interaction instead of hypertext.]

Darrel Miller
+1  A: 

I have implemented multiple REST production systems and have come to the conclusion that the self-documenting aspect of REST is it's most misunderstood and dangerous part (very usable, but must be handled with care). At least don't use it as yet another excuse for not writing an initial spec (it's significantly easier to change the behavior of a program in human code than to do it after the API has been implemented).

However try to keep the documentation lean. It's really very similar to writing ordinary API documentation, where you want the classes/methods to have obvious names/responsibility and you only want to consult the documentation for non-obvious information (such as initial client state and error conditions). If you aim for a similar REST service API then you should be safe.

But do write some documentation! (fx. based on the initial spec). Most people actually do prefer a readable API rather than cycling through a WADL file or looking for wired URI pointers inside XHTML/Atom fragments.

Lars Tackmann
If your representations are hyperlinked and you completely describe the structure of your representations, then by definition you have documented your API. Providing client developers with a list of URIs and the allowed verbs will guarantee the clients they write will be coupled tightly to the server. At which point, you probably would have been better off to use SOAP.
Darrel Miller
The idea that REST provides complete loose coupling is a illusion. As an example if you are using the twitter API (http://apiwiki.twitter.com/Twitter-API-Documentation) then you are by definition required to a) use the correct data format and b) confined to the specified URLs.As for documenting your API I would consider twitter a quit good example and starting point (it being one of the most used Restful APIs).
Lars Tackmann
The problem is that Twitter's API is not RESTful at all. The messages are not self-descriptive, there is little or no hypermedia. The best thing about it is that it is relatively simple.
Darrel Miller
A: 

I'd love to know why you thought Enunciate hard to use.

Ryan Heaton
I have a standard JAX-RS service built with maven. The API package is separate from the implementation package. It wasn't clear how to make enunciate just build documentation. Enunciate seems to want to handle all the packaging and deployment of the service as well. The docs seemed to indicate that you could use only the documentation module, but it was very confusing.
jnorris
I think the following use-case is very common: JAX-RS, maven (where API and implementation are in different maven artifacts) and only documentation is wanted. Perhaps it would be useful to provide an example for this specific use-case.
jnorris
This is documented in the FAQ; it is indeed a common use case. Make sure you use the latest version (1.16, or 1.17 will be released tomorrow) because there has been a lot of improvements on the importing/exporting of already-existing classes.http://docs.codehaus.org/display/ENUNCIATE/Documentation+Only
Ryan Heaton
Thanks Ryan. I'm going to give this another shot soon.
jnorris
I am taking a simple pom (of type war) and adding the configuration as per your link. It works except the docsDir parameter becomes a zip file of the docs instead of the unrolled directory. I have tried many other combinations from the documentation, but no success.
jnorris
This is a bug that is fixed in 1.18 as per enunciate dev mailing list. Thanks.
jnorris