sphinx-contrib / httpdomain / doc / index.rst

:mod:`sphinxcontrib.httpdomain` --- Documenting RESTful HTTP APIs

This contrib extension, :mod:`sphinxcontrib.httpdomain`, provides a Sphinx domain for describing RESTful HTTP APIs.

In order to use it, add :mod:`sphinxcontrib.httpdomain` into :data:`extensions` list of your Sphinx configuration file (:file:`conf.py`):

extensions = ['sphinxcontrib.httpdomain']

Basic usage

There are several provided :ref:`directives <directives>` that describe HTTP resources.

.. http:get:: /users/(int:user_id)/posts/(tag)

   The posts tagged with `tag` that the user (`user_id`) wrote.

   **Example request**:

   .. sourcecode:: http

      GET /users/123/posts/web HTTP/1.1
      Host: example.com
      Accept: application/json, text/javascript

   **Example response**:

   .. sourcecode:: http

      HTTP/1.1 200 OK
      Vary: Accept
      Content-Type: text/javascript

          "post_id": 12345,
          "author_id": 123,
          "tags": ["server", "web"],
          "subject": "I tried Nginx"
          "post_id": 12346,
          "author_id": 123,
          "tags": ["html5", "standards", "web"],
          "subject": "We go to HTML 5"

   :query sort: one of ``hit``, ``created-at``
   :query offset: offset number. default is 0
   :query limit: limit number. default is 30
   :statuscode 200: no error
   :statuscode 404: there's no user

will be rendered as:

Of course, :ref:`roles <roles>` that refer the directives as well. For example:


will render like:



Resource Fields

Inside HTTP resource description directives like :rst:dir:`get`, reStructuredText field lists with these fields are recognized and formatted nicely:

param, parameter, arg, argument
Description of URL parameter.
queryparameter, queryparam, qparam, query
Description of parameter passed by request query string.
formparameter, formparam, fparam, form
Description of parameter passed by request content body, encoded in :mimetype:`application/x-www-form-urlencoded` or :mimetype:`multipart/form-data`.
statuscode, status, code
Description of response status code.

For example:

.. http:post:: /posts/(int:post_id)

   Replies a comment to the post.

   :param post_id: post's unique id
   :type post_id: int
   :form email: author email address
   :form body: comment body
   :status 302: and then redirects to :http:get:`/posts/(int:post_id)`
   :status 400: when form parameters are missing

It will render like this:


:mod:`sphinxcontrib.autohttp.flask` --- Exporting API reference from Flask app

It generates RESTful HTTP API reference documentation from a Flask application's routing table, similar to :mod:`sphinx.ext.autodoc`.

In order to use it, add :mod:`sphinxcontrib.autohttp.flask` into :data:`extensions` list of your Sphinx configuration (:file:`conf.py`) file:

extensions = ['sphinxcontrib.autohttp.flask']

For example:

.. autoflask:: autoflask_sampleapp:app

will be rendered as:

Author and License

The :mod:`sphinxcontrib.httpdomain` and :mod:`sphinxcontrib.autohttp`, parts of :mod:`sphinxcontrib`, are written by Hong Minhee for StyleShare and distributed under BSD license.

The source code is mantained under the common repository of contributed extensions for Sphinx (find the :file:`httpdomain` directory inside the repository).

$ hg clone https://bitbucket.org/birkenfeld/sphinx-contrib
$ cd sphinx-contrib/httpdomain
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.