-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
510 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line. | ||
SPHINXOPTS = | ||
SPHINXBUILD = sphinx-build | ||
SPHINXPROJ = flask-rest-api | ||
SOURCEDIR = . | ||
BUILDDIR = _build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.. _api: | ||
|
||
************* | ||
API Reference | ||
************* | ||
|
||
.. module:: flask_rest_api | ||
|
||
Api | ||
=== | ||
|
||
|
||
.. autoclass:: flask_rest_api.Api | ||
:members: | ||
|
||
Blueprint | ||
========= | ||
|
||
.. autoclass:: flask_rest_api.Blueprint | ||
:members: | ||
|
||
ETag | ||
==== | ||
|
||
.. automodule:: flask_rest_api.etag | ||
:members: | ||
|
||
Pagination | ||
========== | ||
|
||
.. automodule:: flask_rest_api.pagination | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.. include:: ../AUTHORS.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.. _changelog: | ||
|
||
.. include:: ../CHANGELOG.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# This file does only contain a selection of the most common options. For a | ||
# full list see the documentation: | ||
# http://www.sphinx-doc.org/en/master/config | ||
|
||
# -- Path setup -------------------------------------------------------------- | ||
|
||
# If extensions (or modules to document with autodoc) are in another directory, | ||
# add these directories to sys.path here. If the directory is relative to the | ||
# documentation root, use os.path.abspath to make it absolute, like shown here. | ||
# | ||
# import os | ||
# import sys | ||
# sys.path.insert(0, os.path.abspath('.')) | ||
|
||
|
||
# -- Project information ----------------------------------------------------- | ||
|
||
import flask_rest_api | ||
|
||
project = 'flask-rest-api' | ||
copyright = '2018, Nobatek' | ||
|
||
version = release = flask_rest_api.__version__ | ||
|
||
|
||
# -- General configuration --------------------------------------------------- | ||
|
||
# If your documentation needs a minimal Sphinx version, state it here. | ||
# | ||
# needs_sphinx = '1.0' | ||
|
||
# Add any Sphinx extension module names here, as strings. They can be | ||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom | ||
# ones. | ||
extensions = [ | ||
'sphinx.ext.autodoc', | ||
'sphinx.ext.intersphinx', | ||
'sphinx.ext.viewcode', | ||
] | ||
|
||
intersphinx_mapping = { | ||
'python': ('http://python.readthedocs.io/en/latest/', None), | ||
'marshmallow': ('http://marshmallow.readthedocs.io/en/latest/', None), | ||
'webargs': ('http://webargs.readthedocs.io/en/latest/', None), | ||
'flask': ('http://flask.readthedocs.io/en/latest/', None), | ||
} | ||
|
||
# Add any paths that contain templates here, relative to this directory. | ||
templates_path = ['_templates'] | ||
|
||
# The suffix(es) of source filenames. | ||
# You can specify multiple suffix as a list of string: | ||
# | ||
# source_suffix = ['.rst', '.md'] | ||
source_suffix = '.rst' | ||
|
||
# The master toctree document. | ||
master_doc = 'index' | ||
|
||
# The language for content autogenerated by Sphinx. Refer to documentation | ||
# for a list of supported languages. | ||
# | ||
# This is also used if you do content translation via gettext catalogs. | ||
# Usually you set "language" from the command line for these cases. | ||
language = None | ||
|
||
# List of patterns, relative to source directory, that match files and | ||
# directories to ignore when looking for source files. | ||
# This pattern also affects html_static_path and html_extra_path . | ||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] | ||
|
||
# The name of the Pygments (syntax highlighting) style to use. | ||
pygments_style = 'sphinx' | ||
|
||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
|
||
# The theme to use for HTML and HTML Help pages. See the documentation for | ||
# a list of builtin themes. | ||
# | ||
html_theme = 'alabaster' | ||
|
||
# Theme options are theme-specific and customize the look and feel of a theme | ||
# further. For a list of options available for each theme, see the | ||
# documentation. | ||
# | ||
# html_theme_options = {} | ||
|
||
# Add any paths that contain custom static files (such as style sheets) here, | ||
# relative to this directory. They are copied after the builtin static files, | ||
# so a file named "default.css" will overwrite the builtin "default.css". | ||
html_static_path = ['_static'] | ||
|
||
# Custom sidebar templates, must be a dictionary that maps document names | ||
# to template names. | ||
# | ||
# The default sidebars (for documents that don't match any pattern) are | ||
# defined by theme itself. Builtin themes are using these templates by | ||
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', | ||
# 'searchbox.html']``. | ||
# | ||
# html_sidebars = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
flask-rest-api: build a REST API on Flask using Marshmallow | ||
=========================================================== | ||
|
||
Release v\ |version|. (:ref:`Changelog <changelog>`) | ||
|
||
**flask-rest-api** is a framework library for creating REST APIs. | ||
|
||
It uses Flask as a webserver, and marshmallow to serialize and deserialize data. | ||
It relies extensively on the marshmallow ecosystem, using webargs to get arguments | ||
from requests, and apispec to generate an OpenAPI specification file as | ||
automatically as possible. | ||
|
||
|
||
Install | ||
======= | ||
|
||
flask-rest-api requires Python >= 3.5. | ||
|
||
.. code-block:: bash | ||
$ pip install flask-rest-api | ||
Guide | ||
===== | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
quickstart | ||
parameters | ||
response | ||
etag | ||
pagination | ||
openapi | ||
|
||
|
||
API Reference | ||
============= | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
api_reference | ||
|
||
Project Info | ||
============ | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
changelog | ||
license | ||
authors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
License | ||
======= | ||
|
||
.. include:: ../LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@ECHO OFF | ||
|
||
pushd %~dp0 | ||
|
||
REM Command file for Sphinx documentation | ||
|
||
if "%SPHINXBUILD%" == "" ( | ||
set SPHINXBUILD=sphinx-build | ||
) | ||
set SOURCEDIR=. | ||
set BUILDDIR=_build | ||
set SPHINXPROJ=flask-rest-api | ||
|
||
if "%1" == "" goto help | ||
|
||
%SPHINXBUILD% >NUL 2>NUL | ||
if errorlevel 9009 ( | ||
echo. | ||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx | ||
echo.installed, then set the SPHINXBUILD environment variable to point | ||
echo.to the full path of the 'sphinx-build' executable. Alternatively you | ||
echo.may add the Sphinx directory to PATH. | ||
echo. | ||
echo.If you don't have Sphinx installed, grab it from | ||
echo.http://sphinx-doc.org/ | ||
exit /b 1 | ||
) | ||
|
||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% | ||
goto end | ||
|
||
:help | ||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% | ||
|
||
:end | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
.. _parameters: | ||
.. module:: flask_rest_api | ||
|
||
Parameters | ||
========== | ||
|
||
To inject parameters into a view function, use the :meth:`Blueprint.arguments <Blueprint.arguments>` decorator. | ||
|
||
This method takes a :class:`Schema <marshmallow.Schema>` to deserialize and | ||
validate the parameters. | ||
|
||
By default, the parameters are expected to be passed as json in request body. | ||
The location can be specified with the ``location`` parameter. | ||
|
||
Available locations are: | ||
|
||
- ``'querystring'`` or ``'query'`` | ||
- ``'json'`` | ||
- ``'form'`` | ||
- ``'headers'`` | ||
- ``'cookies'`` | ||
- ``'files'`` | ||
|
||
Unlike webargs's :meth:`use_args <webargs.core.Parser.use_args>` decorator, | ||
:meth:`Blueprint.arguments <Blueprint.arguments>` only accepts a single location. | ||
|
||
The input data is deserialized, validated, and injected in the view function as | ||
a dict. | ||
|
||
|
||
.. code-block:: python | ||
:emphasize-lines: 5, 11 | ||
@blp.route('/') | ||
class Pets(MethodView): | ||
@api.doc(summary='List pets') | ||
@api.arguments(PetQueryArgsSchema, location='query') | ||
@api.response(PetSchema(many=True)) | ||
def get(self, args): | ||
return Pet.get(filters=args) | ||
@api.doc(summary='Add a new pet') | ||
@api.arguments(PetSchema) | ||
@api.response(PetSchema, code=201) | ||
def post(self, new_data): | ||
item = Pet.create(**new_data) | ||
return item | ||
Keyword arguments provided to :meth:`Blueprint.arguments <Blueprint.arguments>` | ||
are passed to webargs's :meth:`use_args <webargs.core.Parser.use_args>`. | ||
|
||
If ``as_kwargs=True`` is passed, the decorator passes deserialized input data | ||
as keyword arguments rather than as a single positional ``dict`` argument. | ||
|
||
.. code-block:: python | ||
:emphasize-lines: 5, 7, 8 | ||
@blp.route('/') | ||
class Pets(MethodView): | ||
@api.doc(summary='List pets') | ||
@api.arguments(PetQueryArgsSchema, location='query', as_kwargs=True) | ||
@api.response(PetSchema(many=True)) | ||
def get(self, **kwargs): | ||
return Pet.get(filters=**kwargs) |
Oops, something went wrong.