Sphinx HTTP Domain

2.0.0 · active · verified Fri Apr 10

Sphinxcontrib-httpdomain is an active Sphinx extension (current version 2.0.0) that provides a domain for documenting RESTful HTTP APIs directly within reStructuredText or MyST documentation. It allows authors to describe HTTP resources, methods, request/response headers, query parameters, and status codes, integrating API documentation seamlessly with project documentation. Releases are made as needed, often tied to Sphinx compatibility or feature additions.

Warnings

Install

Imports

Quickstart

To use sphinxcontrib-httpdomain, first add 'sphinxcontrib.httpdomain' to the 'extensions' list in your Sphinx project's `conf.py`. Then, you can define HTTP API endpoints using directives like `.. http:get::` in your reStructuredText or MyST files, detailing paths, parameters, statuses, and examples.

Add `sphinxcontrib.httpdomain` to your `conf.py`:

```python
# conf.py
project = 'My API Docs'
copyright = '2026, Your Name'
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon',
    'sphinxcontrib.httpdomain'
]
```

Then, in a reStructuredText file (e.g., `api.rst`):

```rst
.. http:get:: /users/(int:user_id)
   :synopsis: Get user profile

   Fetches the profile for a specific user.

   :param user_id: The ID of the user to retrieve.
   :type user_id: int
   :status 200: User profile retrieved successfully.
   :status 404: User not found.

   **Example request**:

   .. sourcecode:: http

      GET /users/123 HTTP/1.1
      Host: example.com
      Accept: application/json

   **Example response**:

   .. sourcecode:: http

      HTTP/1.1 200 OK
      Content-Type: application/json

      {
          "id": 123,
          "name": "John Doe",
          "email": "john.doe@example.com"
      }
```

view raw JSON →