From 939b5ea095d3b0ddffb89bccd1bd6511a7afc303 Mon Sep 17 00:00:00 2001 From: Harsha Narayana Date: Sat, 8 Dec 2018 12:34:52 +0530 Subject: [PATCH] update copyright date and add example section with category Signed-off-by: Harsha Narayana --- docs/conf.py | 2 +- docs/index.rst | 1 + docs/sanic/examples.rst | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 docs/sanic/examples.rst diff --git a/docs/conf.py b/docs/conf.py index 7dd7462c..7b70215d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -38,7 +38,7 @@ master_doc = 'index' # General information about the project. project = 'Sanic' -copyright = '2016, Sanic contributors' +copyright = '2018, Sanic contributors' author = 'Sanic contributors' # The version info for the project you're documenting, acts as replacement for diff --git a/docs/index.rst b/docs/index.rst index 7d440e27..10b9e9c1 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -31,6 +31,7 @@ Guides sanic/extensions sanic/contributing sanic/api_reference + sanic/examples Module Documentation diff --git a/docs/sanic/examples.rst b/docs/sanic/examples.rst new file mode 100644 index 00000000..44734c7f --- /dev/null +++ b/docs/sanic/examples.rst @@ -0,0 +1,56 @@ +Examples +======== + +This section of the documentation is a simple collection of example code that can help you get a quick start +on your application development. Most of these examples are categorized and provide you with a link to the +working code example in the `Sanic Repository `_ + + +Basic Examples +-------------- + +This section of the examples are a collection of code that provide a simple use case example of the sanic application. + +Simple Apps +^^^^^^^^^^^ + +A simple sanic application with a single ``async`` method with ``text`` and ``json`` type response. + +.. literalinclude:: ../../examples/teapot.py + +.. literalinclude:: ../../examples/simple_server.py + + +Simple App with ``Sanic Views`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Showcasing the simple mechanism of using :class:`sanic.viewes.HTTPMethodView` as well as a way to extend the same +into providing a custom ``async`` behavior for ``view``. + +.. literalinclude:: ../../examples/simple_async_view.py + + +URL Redirect +^^^^^^^^^^^^ + +.. literalinclude:: ../../examples/redirect_example.py + + +Named URL redirection +^^^^^^^^^^^^^^^^^^^^^ + +``Sanic`` provides an easy to use way of redirecting the requests via a helper method called ``url_for`` that takes a +unique url name as argument and returns you the actual route assigned for it. This will help in simplifying the +efforts required in redirecting the user between different section of the application. + +.. literalinclude:: ../../examples/url_for_example.py + +Custom Logging +^^^^^^^^^^^^^^ + +Even though ``Sanic`` comes with a battery of Logging support it allows the end users to customize the way logging +is handled in the application runtime. + +.. literalinclude:: ../../examples/override_logging.py + +