Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomatically document my REST API
    primarykey
    data
    text
    <p>I am trying to create documentation automatically from the code for all the URLs supported by my application. We are using completely client side MVC, hence each URL that is supported is essentially a REST API for the UI. Is there a easy way to generate the documentation from these URLs?</p> <p>I wrote this small module as of now, but I am looking for better ways then this. I don't want to re-invent the wheel if something similar already exists. </p> <p><strong>UPDATE</strong>: Note the intent is to provide a public documentation for the consumers of the website, not for internal consumption. In this regard, for each URL we need to document: - what is the response, - which parameters are accepted, - if the URL responds to GET/POST or both, etc. </p> <p>Certain URLs like (^$) that simply redirect to home page should not be documented, so I will need some exclusion mechanism as well. </p> <pre><code>from django.core.management.base import BaseCommand from django.conf import settings class Command(BaseCommand): ''' Generates documentation for the URLs. For each URL includes the documentation from the callback implementing the URL and prints the default arguments along with the URL pattern and name''' def handle(self, *args, **options): url_module = None exec 'import '+settings.ROOT_URLCONF+'; url_module='+settings.ROOT_URLCONF doc = file('doc.html','w') doc.write("&lt;table border=1 cellspacing=0 cellpadding=5&gt;") doc.write("&lt;tr&gt;&lt;th&gt;URL Pattern&lt;th&gt;Name&lt;th&gt;Documentation&lt;th&gt;Parameters") for x in url_module.urlpatterns: doc.write("&lt;tr&gt;") doc.write("&lt;td&gt;") doc.write(x._regex) doc.write("&lt;td&gt;") doc.write(str(x.name)) try: documentation = str(x.callback.__doc__) doc.write("&lt;td&gt;&lt;pre&gt;") doc.write(documentation) doc.write("&lt;/pre&gt;") except: doc.write("&lt;td&gt; Unable to find module") doc.write("&lt;td&gt;") doc.write(str(x.default_args)) doc.write("&lt;/table&gt;") doc.close() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload