Source

sphinx-contrib / httpdomain / doc / index.rst

Full commit

: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:

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

will render like:

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

Directives

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`.
jsonparameter, jsonparam, json
Description of a parameter passed by request content body, encoded in :mimetype:`application/json`.
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:

Roles

: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
   :undoc-static:

will be rendered as:

Author and License

The :mod:`sphinxcontrib.httpdomain` and :mod:`sphinxcontrib.autohttp`, parts of :mod:`sphinxcontrib`, are written by Hong Minhee 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

Changelog

Version 1.1.9

To be released.

Version 1.1.8

Released on April 10, 2013.

Version 1.1.7

Released on March 28, 2012.

Version 1.1.6

Released on December 16, 2011.

Version 1.1.5

Released on July 6, 2011.

Version 1.1.4

Released on June 8, 2011.

  • CPython compatibility
  • PyPy compatibility

Version 1.1.3

Released on June 8, 2011.

  • PyPy compatibility

Version 1.1.2

Released on June 4, 2011.

  • Added :include-empty-docstring: flag option.

Version 1.1.1

Released on June 4, 2011.

  • Fixed a backward incompatibility bug.

Version 1.1

Released on June 4, 2011.

Version 1.0

Released on June 2, 2011. The first release.