{ "info": { "author": "Felix Carmona", "author_email": "mail@felixcarmona.com", "bugtrack_url": null, "classifiers": [], "description": "pyrouter\n========\n\n.. image:: https://travis-ci.org/felixcarmona/pyrouter.png?branch=master\n :target: https://travis-ci.org/felixcarmona/pyrouter\n\n.. image:: https://coveralls.io/repos/felixcarmona/pyrouter/badge.png?branch=master\n :target: https://coveralls.io/r/felixcarmona/pyrouter?branch=master\n\n.. image:: https://pypip.in/d/pyrouter/badge.png\n :target: https://pypi.python.org/pypi/pyrouter/\n :alt: Downloads\n\n.. image:: https://pypip.in/v/pyrouter/badge.png\n :target: https://pypi.python.org/pypi/pyrouter/\n :alt: Latest Version\n\nRouting in Action\n=================\nA route is a map from a URL path to a controller.\n\nFor example, suppose you want to match any URL like /blog/my-post or /blog/all-about-cats and send it to a\ncontroller that can look up and render that blog entry info. The route is simple:\n\n.. code-block:: python\n\n ...\n routes = {\n 'blog_show': {\n 'path': '/blog/{slug}',\n 'methods': ['GET'],\n 'controller': 'myapplication.blog.BlogController'\n }\n }\n ...\n\nThe path defined by the ``blog_show`` route acts like ``/blog/*`` where the wildcard is given the name slug.\nFor the URL ``/blog/my-blog-post``, the slug variable gets a value of ``my-blog-post``,\nwhich is available for you to use in your controller (keep reading). The ``blog_show`` is the internal name of the\nroute, which doesn't have any meaning yet and just needs to be unique. Later, you'll use it to generate URLs.\n\nThe ``controller`` parameter is a special key that tells **pyrouter** which controller should be executed when a URL matches\nthis route. The ``controller`` string value point to a specific python module > class:\n\n.. code-block:: python\n :linenos:\n\n # myapplication/blog.py\n from pyhttp import Response\n\n\n class BlogController:\n def __init__(request):\n \"\"\" @type request: pyhttp.Request \"\"\"\n self._request = request\n \n def action(self, slug):\n # use the slug variable to query the database\n post_info = ...\n\n response = Response()\n\n response.data = post_info\n\n return response\n\nCongratulations! You've just created your first route and connected it to a controller.\nNow, when you visit ``/blog/my-post``, the ``action`` method of the ``myapplication.blog.BlogController`` class will be\nexecuted and the ``slug`` variable will be equal to ``my-post``.\n\nThis is the goal of the **pyrouter**: to map the URL of a request to a controller.\nAlong the way, you'll learn all sorts of tricks that make mapping even the most complex URLs easy.\n\nCustomizing the path matching Requirements\n------------------------------------------\n\n\nCreating Routes\n===============\n\nCustomizing the action method name of the controller class\n----------------------------------------------------------\n\nAdding HTTP Method Requirements\n-------------------------------\nIn addition to the URL, you can also match on the *method* of the incoming request (i.e. GET, HEAD, POST, PUT, DELETE).\nSuppose you have a contact form with two controllers - one for displaying the form info (on a GET request) and one for\nprocessing the form when it's submitted (on a POST request).\nThis can be accomplished with the following route configuration:\n\n.. code-block:: python\n\n ...\n routes = {\n 'contact': {\n 'path': '/contact',\n 'methods': ['GET'],\n 'controller': 'myapplication.main.ContactController'\n },\n 'contact_process': {\n 'path': '/contact',\n 'methods': ['POST'],\n 'controller': 'myapplication.main.ContactProcessController'\n }\n }\n ...\n\nDespite the fact that these two routes have identical paths (``/contact``), the first route will match only GET requests\nand the second route will match only POST requests. This means that you can display the form info and submit the form\nvia the same URL, while using distinct controllers for the two actions.\n\n.. note::\n\n If no method is specified, the route will match with *all* valid methods.\n\n According to the *RFC 2616*, the valid HTTP request methods are:\n\n ``GET``, ``HEAD``, ``POST``, ``PUT``, ``DELETE``, ``TRACE``, ``OPTIONS``, ``CONNECT`` and ``PATCH``\n\n.. note::\n\n You can specify multiples methods specifying a list.\n\n All of the following method configurations are valid:\n\n .. code-block:: python\n\n 'methods': ['GET']\n\n .. code-block:: yaml\n\n 'methods': ['GET', 'POST']\n\n\nAdding Protocol Requirements to use HTTPS or HTTP\n-------------------------------------------------\nSometimes, you want to secure some routes and be sure that they are only accessed via the HTTPS protocol.\n\nThis can be accomplished with the following route configuration:\n\n.. code-block:: python\n\n routes = {\n 'contact': {\n 'path': '/contact',\n 'controller': 'myapplication.main.ContactController',\n 'protocols': ['https']\n }\n }\n\n.. note::\n\n If the ``protocols`` directive is not specified, by default the route will match with **HTTP** and **HTTPS**.\n\n.. note::\n\n The protocols will be specified using a list.\n\n All of the following method configurations are valid:\n\n .. code-block:: python\n\n 'protocols': ['http']\n\n .. code-block:: python\n\n 'protocols': ['http', 'https']\n\n\nAdding Host Requirements\n------------------------\n\nConfiguring the Dispatcher\n==========================\n\nControllers Dependencies\n------------------------", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/felixcarmona/pyrouter", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "pyrouter", "package_url": "https://pypi.org/project/pyrouter/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pyrouter/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/felixcarmona/pyrouter" }, "release_url": "https://pypi.org/project/pyrouter/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Associate a request with the code that will convert it to a response", "version": "1.0.0" }, "last_serial": 1342354, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "c7fea9c1402a109e7c8b48071dd862ee", "sha256": "e6ed23204096b16c7690cacbfd77f0624e5e2bd9e755439f895604d772100b3f" }, "downloads": -1, "filename": "pyrouter-1.0.0.tar.gz", "has_sig": false, "md5_digest": "c7fea9c1402a109e7c8b48071dd862ee", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5425, "upload_time": "2014-12-13T12:13:53", "url": "https://files.pythonhosted.org/packages/19/a1/e1cfa9044797b298fc088200796d7f28ca2748ed4cda9e9c32e1f4f442b2/pyrouter-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c7fea9c1402a109e7c8b48071dd862ee", "sha256": "e6ed23204096b16c7690cacbfd77f0624e5e2bd9e755439f895604d772100b3f" }, "downloads": -1, "filename": "pyrouter-1.0.0.tar.gz", "has_sig": false, "md5_digest": "c7fea9c1402a109e7c8b48071dd862ee", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5425, "upload_time": "2014-12-13T12:13:53", "url": "https://files.pythonhosted.org/packages/19/a1/e1cfa9044797b298fc088200796d7f28ca2748ed4cda9e9c32e1f4f442b2/pyrouter-1.0.0.tar.gz" } ] }