sphinx域在rest中标记restful web服务
sphinx-http-domain的Python项目详细描述
说明
sphinx插件添加http域,允许 restful http方法。
这是目前非常初级和实验性的代码。
http方法
您可以记录简单的方法,在路径中包装任何参数 带大括号:
.. http:method:: GET /api/foo/bar/{id}/{slug} :arg id: An id :arg slug: A slug Retrieve list of foobars matching given id.
还支持查询字符串参数,包括强制参数和 可选:
.. http:method:: GET /api/foo/bar/?id&slug :param id: An id :optparam slug: A slug Search for a list of foobars matching given id.
此外,还可以为参数和参数提供类型:
.. http:method:: GET /api/foo/bar/{id}/?slug :arg integer id: An id :optparam string slug: A slug Search for a list of foobars matching given id.
还支持片段:
.. http:method:: GET /#!/username :fragment username: A username Renders a user's profile page.
此外,您还可以用响应代码记录响应:
.. http:method:: POST /api/foo/bar/ :param string slug: A slug :response 201: A foobar was created successfully. :response 400: Create a foobar.
要引用http方法,请使用:http:method::
.. http:method:: GET /api/ :label-name: get-root :title: API root The :http:method:`get-root` contains all of the API.
http响应
记录回复也很简单:
.. http:response:: Foobar object A foobar object looks like this:: .. source-code:: js { 'slug': SLUG } :data string SLUG: A slug :format: JSON
要引用http响应,请使用:http:response::
.. http:response:: Foobar object A :http:response:`foobar-object` is returned when you foo the bar.
安装
运行pip install sphinx-http-domain。
然后,将sphinx_http_domain添加到conf.py:
extensions = ['sphinx_http_domain']