{ "info": { "author": "Felipe Valverde Campos", "author_email": "felipe.valverde.campos@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: POSIX", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", "Topic :: Software Development :: Libraries :: Application Frameworks", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# AutoApi\n\n[](https://pypi.python.org/pypi/auto_api/) [](https://lbesson.mit-license.org/) [](https://travis-ci.org/fvalverd/AutoApi) [](https://coveralls.io/r/fvalverd/AutoApi) [](https://codeclimate.com/github/fvalverd/AutoApi)\n\nThe goal of AutoApi is avoid developing an [API REST](https://en.wikipedia.org/wiki/Representational_state_transfer) at the start of a project, making a prototype easier than usual. AutoApi also has an authentication system and multiple APIs are supported.\n\n## Quickstart\n\nAssuming you have MongoDB server running in *localhost* on the default port without authentication, AutoApi starts as:\n\n```shell\n$ workon api\n(api) $ pip install auto_api\n(api) $ autoapi\n * Running on http://localhost:8686/ (Press CTRL+C to quit)\n ...\n```\n\nA personal agenda is a good example to show how AutoApi works. We will use the *example* API to insert and retrieve items from *agenda* collection.\n\n### Insert\nTo add an item in the agenda, the following HTTP request shows how to do it:\n
\nPOST http://localhost:8686/example/agenda\nContent-Type: application/json\n\n{\n \"name\": \"user\",\n \"email\": \"user@email.com\",\n \"phone\": \"+123 456-789\",\n \"address\": \"123 Street\"\n}\n\nIt's important to add **/example** (API name) before the REST path **/agenda**, because that is the way AutoApi identifies them.\nThe response will contain the id of the created item as:\n```\n{\"id\": \"591a79400000000000000000\"}\n```\n\nWhere the value of *id* will always be a [MongoDB ObjectId](https://docs.mongodb.com/manual/reference/method/ObjectId).\n\n\n### Retrieve\nTo get the previous inserted item in the agenda, is required to know the *id* of the item. The previous response shows the *id* is *591a79400000000000000000*, so the item can be retrieve making the following HTTP request:\n\n\nGET http://localhost:8686/example/agenda/591a79400000000000000000\n\nIn the same way as the insert operation, the API name and the REST path are required, in this case the path is **/agenda/591a79400000000000000000**. The response will contain the initial inserted data and the AutoApi assigned *id*:\n
\n{\n \"id\": \"591a79400000000000000000\",\n \"name\": \"user\",\n \"email\": \"user@email.com\",\n \"phone\": \"+123 456-789\",\n \"address\": \"123 Street\"\n}\n\n\nBut, if you want to retrieve all the items of the agenda, the following HTTP request shows how:\n\nGET http://localhost:8686/example/agenda\n\n\nAnd the response will be:\n
\n[\n {\n \"id\": \"591a79400000000000000000\",\n \"name\": \"user\",\n \"email\": \"user@email.com\",\n \"phone\": \"+123 456-789\",\n \"address\": \"123 Street\"\n },\n ...\n]\n\n\n\n## How does AutoApi work?\n\nAutoApi was develop on [Python](https://www.python.org/) using [Flask](http://flask.pocoo.org/) and [MongoDB](https://www.mongodb.com/), it was thought to support multiples API because AutoApi uses a database to represent an API, thus to differentiate between two APIs it is necessary to add the api name as a prefix in the URL. For instance, to retrieve all the movies from *imdb-copy* API it is necessary to do a **GET** to **/imdb-copy/movies**, but to retrieve the movies from **rottentomatoes-copy** API the URL is **/rottentomatoes-copy/movies**.\n\nAnother important feature of AutoApi is the authentication, but authentication in this develop is at API level, so users can not be shared between APIs, the reason is because AutoApi uses MongoDB users instead of using a collection to store them, so they are related to a database and AutoApi consider a database as an API.\n\n### Configuration file\nAs AutoApi uses MongoDB to store the data, it is necessary to know the location of the database, by default AutoApi will try to connect to the default connection of MongoDB (*localhost*, *27017*) unless a configuration file is given.\n\nThe configuration file stores the configuration for the MongoDB connection (including the authentication credentials), there is a template on this repository that show the syntax and the options, the template is called *server.cfg.default*.\n\nAutoApi can receive a configuration file using two methods, one is defining an environment variable with the name **AUTOAPI_SETTINGS** where the value is the file path. The other way is passing the parameter **config_path** to the constructor of AutoApi object with the file path.\n\nIf you are going to use the given script to run AutoApi, you can provide [the configuration file as a parameter with the flag *-f*](#running-autoapi), that script uses one of the previous options.\n\n## **AutoApi features**\n\n### Authentication & Authorization\n\nAutoApi authentication is optional, by default it is not activated. To activate it is necessary:\n - [MongoDB auth](#mongodb) activated\n - [AutoApi configuration file](#configuration-file) filled\n - [Run AutoApi server](running-autoapi) with --auth flag\n\n#### Authentication\n\nEach API has their own users, so users have to logged specifying the API in the request:\n\n\nPOST /login\nContent-Type: application/json\n\n{\n \"api\": \"example\",\n \"email\": \"user@email.com\",\n \"password\": \"pass\"\n}\n\n\nThe response will contain a session token in the headers and body:\n\n\nX-Email: user@email.com\nX-Token: 123456\n\n{\n \"email\": \"user@email.com\",\n \"token\": \"123456\"\n}\n\n\nTo logout, users have to specify the API too:\n\n\nPOST /logout\nContent-Type: application/json\nX-Email: user@email.com\nX-Token: 123456\n\n{\"api\": \"example\"}\n\n\n#### Users and Authorization\n\n**Only admin users** can create more users specifying the API and CRUD roles:\n\n\nPOST /user\nContent-Type: application/json\nX-Email: ADMIN_USER\nX-Token: ADMIN_USER_TOKEN\n\n{\n \"email\": \"other_user@email.com\",\n \"password\": \"pass\",\n \"api\": \"example\",\n \"roles\": [\"read\", \"update\"]\n}\n\n\nThe last request creates the user *other_user@email.com* and authorizes him to *read* and *update* the *example* API without any API creation request.\n\nEach user can update his own password and only an admin user can change other users password . The change can be done using the following request:\n\nPOST /password\nContent-Type: application/json\nX-Email: USER\nX-Token: USER_TOKEN\n\n{\n \"email\": \"other_user@email.com\",\n \"password\": \"new-pass\",\n \"api\": \"example\"\n}\n\n\nIt is important to note that the request needs the *email* parameter to select to user that will change the password.\n\nFinally, only an admin user can change the authorization roles for a particular user using the following request:\n\nPOST /roles\nContent-Type: application/json\nX-Email: ADMIN_USER\nX-Token: ADMIN_USER_TOKEN\n\n{\n \"email\": \"other_user@email.com\",\n \"api\": \"example\",\n \"roles\": {\n \"update\": false,\n \"delete\": true\n }\n}\n\n\n\n### Collections and Resources\n\n#### API\n\nTo use an API in AutoApi it is not necessary to create it, it is created on demand and there is no operations related for path **/api**.\n\n#### API collection\n\nTo use and API collection in AutoApi it is not necessary to create it, it is also created on demand.\n\n#### CRUD collection's resources\n\nIt is important to remember that if AutoApi's authentication is enabled then only logged users, with the respective authorization, can CRUD API's resources.\n\nA good API REST example is to show how to mark as a classic all the movies where *actor_1* appears.\n\n\nPATCH /example/actors/actor_1/movies\nContent-Type: application/json\nX-Email: user@email.com\nX-Token: USER_TOKEN\n\n{\"classic\": true}\n\n\nMore info about REST:\n\n- http://www.restapitutorial.com/lessons/httpmethods.html\n- http://restful-api-design.readthedocs.org/en/latest/\n\n\n\n## Dependencies and configuration\n\n#### Installation\n\nI strongly recommend you to use [virtualenv](https://virtualenv.pypa.io) and [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io).\n\n\n$ workon api\n(api) $ pip install auto_api\n\n\n\n#### MongoDB\n\nAutoApi doesn't required modifications on MongoDB configuration to handle APIs, collectios or resources. But, if you want to activate [Authentication](#authentication) and [Authorization](#authorization), as AutoApi uses MongoDB users, it is necessary to set *auth=true* in your *mongodb.cfg* or run *mongod* with the flag *--auth* and you must to provide the MongoDB admin information inside the [AutoApi configuration file](#configuration-file)\n\nRelated info:\n- http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/\n- http://docs.mongodb.org/manual/core/authentication\n- http://docs.mongodb.org/manual/core/authorization\n- http://docs.mongodb.org/manual/tutorial/add-user-administrator\n\n\n## Running AutoApi\n\nAfter [installing AutoApi](#installation) it will be created an executable called **autoapi** and the python module **auto_api**. Also, remember that if you want to run AutoApi with authentication, you must first [turn on the authentication in MongoDB](#mongodb) and then provide the flags **-a** (or **--auth**) and **-f** (or **--config**) with a configuration file based on *server.cfg.default* (located on this repository) to the following commands:\n\n
\n(api) $ autoapi [[-a] -f server.cfg]\n\nor\n
\n(api) $ python -m auto_api [[-a] -f server.cfg]\n\n\n## Testing AutoApi\n\nTo run the AutoApi test there is a script called *run_tests.py*, that automatically start and stop two MongoDB servers for testing purpose only (one with authentication enabled).\n\n
\n(api) $ ./run_tests.py [pytest-parameters]\n\n\nor\n\n
\n(api) $ python setup.py run_tests [-a '[pytest-parameters]']\n\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/fvalverd/AutoApi/tarball/v2.0.2", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/fvalverd/AutoApi", "keywords": "api rest authentication mongodb automatic web flask json", "license": "MIT license", "maintainer": "", "maintainer_email": "", "name": "auto-api", "package_url": "https://pypi.org/project/auto-api/", "platform": "", "project_url": "https://pypi.org/project/auto-api/", "project_urls": { "Download": "https://github.com/fvalverd/AutoApi/tarball/v2.0.2", "Homepage": "https://github.com/fvalverd/AutoApi", "Source": "https://github.com/fvalverd/AutoApi", "Tracker": "https://github.com/fvalverd/AutoApi/issues" }, "release_url": "https://pypi.org/project/auto-api/2.0.2/", "requires_dist": [ "click (>=6.7)", "Flask (>=1.0.2)", "Flask-Cors (>=3.0.7)", "pymongo (<4,>=3.7.2)" ], "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "summary": "Automatic Web API REST", "version": "2.0.2" }, "last_serial": 5149765, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "f42235ef871b41ff6428b3226ad3aa24", "sha256": "2352c5497aa4c95cb2c86368eae712d1a876e480f18675e20c6a41bb31b94332" }, "downloads": -1, "filename": "auto_api-0.0.1.tar.gz", "has_sig": false, "md5_digest": "f42235ef871b41ff6428b3226ad3aa24", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5893, "upload_time": "2015-11-06T01:09:11", "url": "https://files.pythonhosted.org/packages/f9/cd/3403cb5f0ecb1f2cfeb9d791d9144e2fc3fe5234c0db01d3a4bb9d70f16b/auto_api-0.0.1.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "00a8759098e7412e305179a68a5c3bbf", "sha256": "b1635a6cbc9d45054609b7462932b0297bea4c3f4327f6603fa58b02048295d4" }, "downloads": -1, "filename": "auto_api-1.0.1.tar.gz", "has_sig": false, "md5_digest": "00a8759098e7412e305179a68a5c3bbf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8606, "upload_time": "2017-06-02T16:49:01", "url": "https://files.pythonhosted.org/packages/dd/9d/daf338552e21525053dd5e84a4fec31edc9b1eb57ece646dafc0ba5ea88f/auto_api-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "31f1281725fc0abff8740c4076c33773", "sha256": "abc7da681a2ee9c35cad531ef118771eb7f896d1f30c0cf4ffef9dfdb552a6ce" }, "downloads": -1, "filename": "auto_api-1.0.2.tar.gz", "has_sig": false, "md5_digest": "31f1281725fc0abff8740c4076c33773", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8852, "upload_time": "2017-06-08T16:47:10", "url": "https://files.pythonhosted.org/packages/e7/8a/a24d654b6e5ffec40e52cf8ac71cd93f3be22a05631673aea539b6da6edc/auto_api-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "d7b9fa37ca113804243df53f9a834fd5", "sha256": "bbbaf17d15994a52483e55eb0077d2edf3ae7f18aa3ef4af2cbd368c405d1079" }, "downloads": -1, "filename": "auto_api-1.0.3-py2-none-any.whl", "has_sig": false, "md5_digest": "d7b9fa37ca113804243df53f9a834fd5", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 16565, "upload_time": "2017-06-18T23:47:14", "url": "https://files.pythonhosted.org/packages/47/49/af5059a28e90525e76af4fc9c13a66f3c646c4c8292be965784cbf5f2cb8/auto_api-1.0.3-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ac4f726490cb9f05b9f3095ae282606d", "sha256": "e2e4c7d6749f4b9d531387506ce06806e19f851f2cf7bfaf29ee9fca25639764" }, "downloads": -1, "filename": "auto_api-1.0.3.tar.gz", "has_sig": false, "md5_digest": "ac4f726490cb9f05b9f3095ae282606d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9573, "upload_time": "2017-06-18T23:47:16", "url": "https://files.pythonhosted.org/packages/f1/1b/7961ad1f8e5a8b85fc6a5235d17656a3a6dc8197fac6ea27bc97fc2ac21d/auto_api-1.0.3.tar.gz" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "d834e13989ad43bf33695fccba429837", "sha256": "7dd77bf80673e0dc0c42251b3e857706b6d800d037588da51b95dfccd4b97465" }, "downloads": -1, "filename": "auto_api-2.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d834e13989ad43bf33695fccba429837", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 19593, "upload_time": "2019-04-16T11:40:06", "url": "https://files.pythonhosted.org/packages/d3/d6/c46a9c104abd9a217faa7ee33527399a3ca29682538c7d904a133c3769d9/auto_api-2.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ba88ce014f50026ed76d447a81ee1a1c", "sha256": "72d010778a76489e177e515c800ae3c59e2cf349f4cf42e256ab2c90522157d0" }, "downloads": -1, "filename": "auto_api-2.0.1.tar.gz", "has_sig": false, "md5_digest": "ba88ce014f50026ed76d447a81ee1a1c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 18498, "upload_time": "2019-04-16T11:40:07", "url": "https://files.pythonhosted.org/packages/7d/e8/00a58f1cf5ed9192be25e68f812d63e0271eb6cca0b8f8b46ff29097fd23/auto_api-2.0.1.tar.gz" } ], "2.0.2": [ { "comment_text": "", "digests": { "md5": "6912d70b7e9658a1a88377e69f07e5ba", "sha256": "123fc155bd8db2494c9440eb9d74d856d102430b8ebddcecb7f64779f6fd1ec0" }, "downloads": -1, "filename": "auto_api-2.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6912d70b7e9658a1a88377e69f07e5ba", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 19525, "upload_time": "2019-04-16T12:19:13", "url": "https://files.pythonhosted.org/packages/c7/69/599661658dc64870d8fc24531dbd8a0815c82f3a9b10a16180444243dd2a/auto_api-2.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fef765a31a9eb1860670eb576a7ed212", "sha256": "9ee4bd33ee67a9b44034c61799d06ba040de1882a6eff9bc5ae0f8528ba2073e" }, "downloads": -1, "filename": "auto_api-2.0.2.tar.gz", "has_sig": false, "md5_digest": "fef765a31a9eb1860670eb576a7ed212", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 18383, "upload_time": "2019-04-16T12:19:15", "url": "https://files.pythonhosted.org/packages/a1/c4/6a9090b030de080d6b47ebe4189a3a157d19df74ff1227f4c2b8c5c951ac/auto_api-2.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6912d70b7e9658a1a88377e69f07e5ba", "sha256": "123fc155bd8db2494c9440eb9d74d856d102430b8ebddcecb7f64779f6fd1ec0" }, "downloads": -1, "filename": "auto_api-2.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6912d70b7e9658a1a88377e69f07e5ba", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 19525, "upload_time": "2019-04-16T12:19:13", "url": "https://files.pythonhosted.org/packages/c7/69/599661658dc64870d8fc24531dbd8a0815c82f3a9b10a16180444243dd2a/auto_api-2.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fef765a31a9eb1860670eb576a7ed212", "sha256": "9ee4bd33ee67a9b44034c61799d06ba040de1882a6eff9bc5ae0f8528ba2073e" }, "downloads": -1, "filename": "auto_api-2.0.2.tar.gz", "has_sig": false, "md5_digest": "fef765a31a9eb1860670eb576a7ed212", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", "size": 18383, "upload_time": "2019-04-16T12:19:15", "url": "https://files.pythonhosted.org/packages/a1/c4/6a9090b030de080d6b47ebe4189a3a157d19df74ff1227f4c2b8c5c951ac/auto_api-2.0.2.tar.gz" } ] }