{ "info": { "author": "Timothy Corbett-Clark", "author_email": "timothy@corbettclark.com", "bugtrack_url": null, "classifiers": [], "description": "REST API Blueprint\n==================\n\nThis is an exploration into how best to create a REST API using `Python\n`_ (version 2.7) and the excellent micro-web framework\n`Flask `_. It aims to be a pedagogical blueprint rather\nthan a library or utility. A more prosaic and honest statement of the goal is to\nprovide a clean exposition *with code* of *my* current (but evolving) tastes in\nthe design and structure of a REST API built with Python and Flask.\n\nThe scope includes automatic testing, documentation, authentication, capability\nswitching, data formats, mime types, and unicode. As the focus is on REST API\nstructure and expression, the scope does *not* include things like ORM's and\ntemplating engines.\n\nSee the `Wiki `_ for discussion and explanation. Otherwise the `repository\ncode `_ is\nauthoritative.\n\nNote that this is not a library so much as an approach to be read and copied.\nHowever there are clearly parts which are usefully referenced (e.g. the BDD\n`steps `_ or the `lib\n`_). This is possible by installing as a package and importing.\n\nStatus\n------\n\nReasonably complete now. See `open issues `_.\n\nQuick tour\n----------\n\nStart the example app server:\n\n::\n\n -/code/rest-api-blueprint$ python server.py\n * Running on http://127.0.0.1:5000/\n * Restarting with reloader\n ...\n\nAdd person details with the `example app `_:\n\n::\n\n ~/code/rest-api-blueprint$ curl -X PUT localhost:5000/v1/people/fred -H 'Content-Type: application/json' -d '{\"email\": \"a@b.c\"}'\n {\n \"status\": \"ok\"\n }\n\nRetrieve person details with the `example app`_:\n\n::\n\n ~/code/rest-api-blueprint$ curl -X GET localhost:5000/v1/people/fred -H 'Accept: application/json'\n {\n \"status\": \"ok\",\n \"result\": {\n \"comment\": null,\n \"name\": \"fred\",\n \"email\": \"a@b.c\"\n }\n }\n\nRun the BDD tests (`BDD details `_):\n\n::\n\n ~/code/rest-api-blueprint$ behave\n Feature: Delete a person # features/delete_person.feature:1\n As an API client\n I want to be able to remove a person\n\n Background: Reset and have a valid user # features/delete_person.feature:5\n\n Scenario: Cannot delete a person before they exist # features/delete_person.feature:11\n Given I am using version \"v1\" # features/steps/all.py:14\n And I have an empty database # features/steps/all.py:19\n And I am a valid API user # features/steps/all.py:27\n And I use an Accept header of \"application/json\" # features/steps/all.py:32\n When I send a DELETE request to \"people/fred\" # features/steps/all.py:101\n Then the response status should be \"404\" # features/steps/all.py:109\n And the JSON at path \"status\" should be \"error\" # features/steps/all.py:119\n And the JSON at path \"message\" should be \"Person does not exist\" # features/steps/all.py:119\n\n Scenario: Delete a person # features/delete_person.feature:17\n Given I am using version \"v1\" # features/steps/all.py:14\n ...\n\nMake the API docs (`Doc details `_):\n\n::\n\n ~/code/rest-api-blueprint$ ./make_apidocs.sh\n Making output directory...\n Running Sphinx v1.1.3\n loading pickled environment... not yet created\n building [html]: targets for 2 source files that are out of date\n updating environment: 2 added, 0 changed, 0 removed\n reading sources... [100%] people\n looking for now-outdated files... none found\n pickling environment... done\n checking consistency... done\n preparing documents... done\n writing output... [100%] people\n writing additional files... search\n copying static files... done\n dumping search index... done\n dumping object inventory... done\n build succeeded.\n Copying ansi stylesheet... done\n\nBe redirected to the on-line docs:\n\n::\n\n ~/code/rest-api-blueprint$ curl -X GET localhost:5000/v1/people/fred\n \n Redirecting...\n

Redirecting...

\n

You should be redirected automatically to target URL: static/apidocs/people.html. If not click the link.\n\nInteracting using `Slumber `_:\n\n::\n\n >>>import slumber\n >>>api=slumber.API('http://localhost:5000/v1/', append_slash=False)\n >>>api.people.tim.put({\"email\": \"a@b.c\"})\n True\n\n >>>api.people.tim.get()\n {u'result': {u'comment': None, u'email': u'a@b.c', u'name': u'tim'}, u'status': u'ok'}\n\nTo provide a template packaged structure, everything is packaged using\n`distribute `_.\n\nTo run the tests:\n\n::\n\n python setup.py nosetests\n\nTo build a package for distribution and installation with pip etc:\n\n::\n\n python setup.py sdist\n\nThe package is in the ``dist/`` directory, and can be installed with\n\n::\n\n pip install rest-api-blueprint-0.1.tar.gz\n\nTo install during development:\n\n::\n\n python setup.py develop\n\nor\n\n::\n\n pip install -e .\n\n(which will also install any dependent packages.)\n\nWhat's next?\n------------\n\nIntrigued? Read the `Wiki`_ and check out the `code\n`_.\n\nPlease send me feedback, raise bugs or requests using the bitbucket Issue\nTracker, or clone and improve (ideally with create pull requests) as per the\npermissive BSD 2-Clause `license `_.\n", "description_content_type": null, "docs_url": null, "download_url": null, "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://bitbucket.org/tcorbettclark/rest-api-blueprint/", "keywords": null, "license": "This code is made available under the BSD 2-Clause License", "maintainer": null, "maintainer_email": null, "name": "rest-api-blueprint", "package_url": "https://pypi.org/project/rest-api-blueprint/", "platform": null, "project_url": "https://pypi.org/project/rest-api-blueprint/", "project_urls": { "Homepage": "http://bitbucket.org/tcorbettclark/rest-api-blueprint/" }, "release_url": "https://pypi.org/project/rest-api-blueprint/0.1/", "requires_dist": null, "requires_python": null, "summary": "Pedagogical blueprint of a REST API in Flask.", "version": "0.1" }, "last_serial": 764958, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "243888ad62ac888d194881deb55fb892", "sha256": "d67677cbbb0e183a5cda4cff208d349dd4b721f82d2df7dddc5470f7f9f6642d" }, "downloads": -1, "filename": "rest-api-blueprint-0.1.tar.gz", "has_sig": false, "md5_digest": "243888ad62ac888d194881deb55fb892", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 83925, "upload_time": "2012-11-06T18:01:17", "url": "https://files.pythonhosted.org/packages/3d/c1/520fc4dbe9146eb1f859073ef06d76485a9eb78f2f008ea7a42591005f12/rest-api-blueprint-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "243888ad62ac888d194881deb55fb892", "sha256": "d67677cbbb0e183a5cda4cff208d349dd4b721f82d2df7dddc5470f7f9f6642d" }, "downloads": -1, "filename": "rest-api-blueprint-0.1.tar.gz", "has_sig": false, "md5_digest": "243888ad62ac888d194881deb55fb892", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 83925, "upload_time": "2012-11-06T18:01:17", "url": "https://files.pythonhosted.org/packages/3d/c1/520fc4dbe9146eb1f859073ef06d76485a9eb78f2f008ea7a42591005f12/rest-api-blueprint-0.1.tar.gz" } ] }