.. sphinxcontrib-httpdomain documentation master file, created by sphinx-quickstart on Thu Jun 2 13:27:52 2011. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. .. module:: sphinxcontrib.httpdomain :mod:`sphinxcontrib.httpdomain` --- Documenting RESTful HTTP APIs ================================================================= This contrib extension, :mod:`sphinxcontrib.httpdomain`, provides a Sphinx domain for describing RESTful HTTP APIs. .. seealso:: We might support reflection for web framework your webapp depends on. See the following :mod:`sphinxcontrib.auttohttp` modules: Module :mod:`sphinxcontrib.autohttp.flask` Reflection for Flask_ webapps. Module :mod:`sphinxcontrib.autohttp.bottle` Reflection for Bottle_ webapps. Module :mod:`sphinxcontrib.autohttp.tornado` Reflection for Tornado_ webapps. In order to use it, add :mod:`sphinxcontrib.httpdomain` into :data:`extensions` list of your Sphinx configuration file (:file:`conf.py`):: extensions = ['sphinxcontrib.httpdomain'] Additional Configuration ------------------------ ``http_headers_ignore_prefixes`` List of HTTP header prefixes which should be ignored in strict mode:: http_headers_ignore_prefixes = ['X-'] .. versionadded:: 1.3.1 ``http_index_ignore_prefixes`` Strips the leading segments from the endpoint paths by given list of prefixes:: http_index_ignore_prefixes = ['/internal', '/_proxy'] .. versionadded:: 1.3.0 ``http_index_shortname`` Short name of the index which will appears on every page:: http_index_shortname = 'api' .. versionadded:: 1.3.0 ``http_index_localname`` Full index name which is used on index page:: http_index_shortname = "My Project HTTP API" .. versionadded:: 1.3.0 ``http_strict_mode`` When ``True`` (default) emits build errors when status codes, methods and headers are looks non-standard:: http_strict_mode = True .. versionadded:: 1.3.1 Basic usage ----------- There are several provided :ref:`directives ` that describe HTTP resources. .. sourcecode:: rst .. 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 :reqheader Accept: the response content type depends on :mailheader:`Accept` header :reqheader Authorization: optional OAuth token to authenticate :resheader Content-Type: this depends on :mailheader:`Accept` header of request :statuscode 200: no error :statuscode 404: there's no user will be rendered as: .. 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 :reqheader Accept: the response content type depends on :mailheader:`Accept` header :reqheader Authorization: optional OAuth token to authenticate :resheader Content-Type: this depends on :mailheader:`Accept` header of request :statuscode 200: no error :statuscode 404: there's no user Of course, :ref:`roles ` that refer the directives as well. For example: .. sourcecode:: rst :http:get:`/users/(int:user_id)/posts/(tag)` will render like: :http:get:`/users/(int:user_id)/posts/(tag)` .. _directives: Directives ---------- .. rst:directive:: .. http:options:: path Describes a HTTP resource's :http:method:`OPTIONS` method. It can also be referred by :rst:role:`http:options` role. .. rst:directive:: .. http:head:: path Describes a HTTP resource's :http:method:`HEAD` method. It can also be referred by :rst:role:`http:head` role. .. rst:directive:: .. http:post:: path Describes a HTTP resource's :http:method:`POST` method. It can also be referred by :rst:role:`http:post` role. .. rst:directive:: .. http:get:: path Describes a HTTP resource's :http:method:`GET` method. It can also be referred by :rst:role:`http:get` role. .. rst:directive:: .. http:put:: path Describes a HTTP resource's :http:method:`PUT` method. It can also be referred by :rst:role:`http:put` role. .. rst:directive:: .. http:patch:: path Describes a HTTP resource's :http:method:`PATCH` method. It can also be referred by :rst:role:`http:patch` role. .. rst:directive:: .. http:delete:: path Describes a HTTP resource's :http:method:`DELETE` method. It can also be referred by :rst:role:`http:delete` role. .. rst:directive:: .. http:trace:: path Describes a HTTP resource's :http:method:`TRACE` method. It can also be referred by :rst:role:`http:trace` role. .. rst:directive:: .. http:copy:: path Describes a HTTP resource's :http:method:`COPY` method. It can also be referred by :rst:role:`http:copy` role. .. versionadded:: 1.3.0 .. rst:directive:: .. http:any:: path Describes a HTTP resource's which accepts requests with :http:method:`ANY` method. Useful for cases when requested resource proxying the request to some other location keeping original request context. It can also be referred by :rst:role:`http:any` role. .. versionadded:: 1.3.0 Options ``````` .. versionadded:: 1.3.0 Additionally, you may specify custom options to the directives: ``noindex`` Excludes specific directive from HTTP routing table. .. sourcecode:: rst .. http:get:: /users/(int:user_id)/posts/(tag) :noindex: ``deprecated`` Marks the method as deprecated in HTTP routing table. .. sourcecode:: rst .. http:get:: /users/(int:user_id)/tagged_posts :deprecated: ``synopsis`` Adds short description for HTTP routing table. .. sourcecode:: rst .. http:get:: /users/(int:user_id)/posts/(tag) :synopsis: Returns posts by the specified tag for the user .. _resource-fields: 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. It optionally can be typed, all the query parameters will have obviously string types though. But it's useful if there's conventions for it. .. versionchanged:: 1.1.9 It can be typed e.g.: .. sourcecode:: rst :query string title: the post title :query string body: the post body :query boolean sticky: whether it's sticky or not ``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`. .. deprecated:: 1.3.0 Use ``reqjsonobj``/``reqjson``/``jsonobj``, ``>json`` Description of a single field of JSON object returned with response body, encoded in :mimetype:`application/json`. .. sourcecode:: rst :>json boolean ok: Operation status .. versionadded:: 1.3.0 ``reqjsonarr``, ``jsonarr`` Similar to ``json`` respectively, but uses for describing objects schema inside of returned array. Let's say, the response contains the following data: .. sourcecode:: javascript [{"id": "foo", "ok": true}, {"id": "bar", "error": "forbidden", "reason": "sorry"}] Then we can describe it in the following way: .. sourcecode:: rst :>jsonarr boolean ok: Operation status. Not present in case of error :>jsonarr string id: Object ID :>jsonarr string error: Error type :>jsonarr string reason: Error reason .. versionadded:: 1.3.0 .. sourcecode:: rst :>json boolean status: Operation status ``requestheader``, ``reqheader``, ``>header`` Description of request header field. .. versionadded:: 1.1.9 ``responseheader``, ``resheader``, ``