{ "info": { "author": "Tim Rainbow", "author_email": "tim@timrainbow.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: Unix", "Programming Language :: Python :: 3 :: Only", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Application Frameworks", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "RASBlite - Lightweight RESTful API Server Builder\n=================================================\n\nRASBlite allows you to quickly define a data model that you can interact\nwith via a RESTful API in a consistent way. Although there are numerous\nscenarios when you\u2019d want to do this, it is particularly useful during\nthe development of REST clients (such as in unit tests and continuous\nintegration environments).\n\nImagine you\u2019re working on a client that accesses some remote resource\nusing a RESTful API. For example, let\u2019s say your client will interact\nwith a server holding a list of items which includes the name and the\namount of the item. If the server does not yet exist, how will you test\nyour client? If the server does exist, how can you automatically test\nyour client consistently without having constant direct access to the\nserver? For this example, we could easily define a hierarchical model\nwith RASBlite like so:\n\n.. code:: ini\n\n [Base]\n url = /api/\n\n [Model]\n structure = \n GET,POST items/\n GET,PUT,DELETE items/:item_number/\n GET,PUT items/:item_number/name\n GET,PUT items/:item_number/amount\n\nWith RASBlite, your REST client could now perform a HTTP ``POST`` to\n``http://127.0.0.1:8080/api/items/`` with\n``{'name': 'Spoon', 'amount': '3'}`` and then verify it worked by\nsubsequently doing a HTTP ``GET`` to\n``http://127.0.0.1:8080/api/items/0/`` and checking the response matched\nyour earlier ``POST``.\n\nQuickstart\n----------\n\n| Install RASBlite using ``pip3`` - ``$ pip3 install rasblite``, this\n will provide the script\n| ``rasblite-run``. If you encounter an error during installation, you\n may have to run with elevated privileges using ``sudo`` -\n ``$ sudo pip3 install rasblite``.\n\nNext, create a file containing your model called ``model.txt``. To begin\nwith you can just fill the contents with the one below which contains a\nlist of users, their names and any addresses they may have on record:\n\n.. code:: ini\n\n [Base]\n url = /rest/api/1.0/\n\n [Model]\n structure = \n GET,POST users/\n GET,PUT,DELETE users/:userID/\n GET,PUT users/:userID/name\n GET,POST users/:userID/addresses/\n GET,PUT,DELETE users/:userID/addresses/:address/\n GET,PUT users/:userID/addresses/:address/address_lines\n GET,PUT users/:userID/addresses/:address/post_code\n GET,PUT users/:userID/age\n\nNow, if we wanted to start off with no initial data on the server you\ncan simply run:\n\n.. code:: bash\n\n $ rasblite-run --model model.txt --starting_data DEFAULT\n\nOtherwise if you want start with some example data for this particular\nmodel you can create a file called ``data.json`` with the contents:\n\n::\n\n {'users': [{'addresses': [{'address_lines': '123 Fake Street', 'post_code': 'AB12 3CD'}], 'age': '21', 'name': 'Bob'}, {'addresses': [{'address_lines': '456 My Street', 'post_code': 'EF45 6GH'}, {'address_lines': '789 Other Street', 'post_code': 'IJ12 3KL'}], 'age': '60', 'name': 'Frank'}]}\n\nand run it with:\n\n.. code:: bash\n\n $ rasblite-run --model model.txt --starting_data data.json\n\nor\n\n.. code:: bash\n\n $ rasblite-run -m model.txt -d data.json\n\nFeeling lazy? The above starting data is pre-built into the script so\nyou can get the same effect without creating the initial data file by\nrunning:\n\n.. code:: bash\n\n $ rasblite-run -m model.txt -d EXAMPLE\n\nYour HTTP server should now be running and you can easily test it works\nby accessing it with your favourite web bowser:\n\nhttp://127.0.0.1:8080/rest/api/1.0/users/\n\nIf all went well you should see your starting data returned. You can\ndrill down to specific points by following the hierarchy:\n\nhttp://127.0.0.1:8080/rest/api/1.0/users/1/addresses/0/post_code/\n\nYou can now perform all your usual REST functions with HTTP methods such\nas ``GET``, ``POST``, ``PUT`` and ``DELETE``. The model you used\nspecifies which of these HTTP methods are allowed and are determined by\nyou (more on this below in the **Model Structure** section).\n\n--------------\n\n**NOTE:**\n\nMake sure to set the correct HTTP headers in your client for ``POST``\nand ``PUT`` requests. Currently, the only ``content-type`` supported is\n``application/json`` and you need to include the correct\n``content-length`` too. For example, an example raw ``POST`` request\nmight look like:\n\n::\n\n POST /rest/api/1.0/users HTTP/1.1\n HOST: 127.0.0.1:8080\n content-length: 103\n content-type: application/json\n\n {\"name\": \"Jim\", \"addresses\": [{\"post_code\": \"UR98 7ST\", \"address_lines\": \"30 Flat Road\"}], \"age\": \"18\"}\n\n--------------\n\nUsage\n-----\n\n::\n\n $ rasblite-run --help\n usage: rasblite-run [-h] --model MODEL [--starting_data STARTING_DATA]\n [--port PORT]\n\n Lightweight RESTful API Server Builder Command Line Tool\n\n optional arguments:\n -h, --help show this help message and exit\n --model MODEL, -m MODEL\n --starting_data STARTING_DATA, -d STARTING_DATA\n --port PORT, -p PORT\n\nChanging the server port\n~~~~~~~~~~~~~~~~~~~~~~~~\n\nTo use another port other than ``8080``, simply pass the desired port\nnumber to rasblite-run with ``--port`` or ``-p`` argument:\n\n.. code:: bash\n\n $ rasblite-run --model model.txt --starting_data DEFAULT --port 50000\n\nInitialising without hierarchical data store\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIt\u2019s possible to tell RASBlite not to create a hierarchical data store\nto match your model structure. To do this, pass ``EMPTY`` for the\n``--starting_data`` argument:\n\n.. code:: bash\n\n $ rasblite-run --model model.txt --starting_data EMPTY\n\nModel Syntax\n------------\n\nBase URL\n~~~~~~~~\n\nMost REST APIs contain a base url (the part in the url before the\nhierarchical structure). i.e.\n\n``http://:``\n\nYou can set the base url for your API by setting the ``url`` attribute\nwithin the ``[Base]`` section. The path prefix will then be used for\nyour API.\n\nFor example:\n\n.. code:: ini\n\n [Base]\n url = /rest/api/1.0/\n ...\n\nThe above would mean the client must request with ``/rest/api/1.0/``\nbefore their model i.e. ``http://127.0.0.1:8080/rest/api/1.0/some/path``\n\nModel Structure\n~~~~~~~~~~~~~~~\n\nTo define the structure of your model, you must include the possible\nrequest suffix paths with the ``structure`` attribute under a\n``[Model]`` section like so:\n\n.. code:: ini\n\n ...\n\n [Model]\n structure = \n GET,POST users/\n GET,PUT,DELETE users/:userID/\n GET,PUT users/:userID/name\n GET,POST users/:userID/addresses/\n GET,PUT,DELETE users/:userID/addresses/:address/\n GET,PUT users/:userID/addresses/:address/address_lines\n GET,PUT users/:userID/addresses/:address/post_code\n GET,PUT users/:userID/age\n\nEach line contains the approved HTTP methods for that entry and the\nhierarchical suffix path. The parts need to be separated by whitespace\nbut this can be spaces or tabs.\n\nApproved HTTP methods\n^^^^^^^^^^^^^^^^^^^^^\n\nEach line in the structure must start with the HTTP methods that are\nallowed. They have to be comma separated and must be ``GET``, ``POST``,\n``PUT`` and/or ``DELETE``. For example, if you only wanted to allow\nclients to perform a ``GET``, ``POST`` or ``DELETE`` to\n``http://:/base/users/`` your model structure could look\nlike this:\n\n.. code:: ini\n\n [Base]\n url = /base/\n\n [Model]\n structure = \n GET,POST,DELETE users/\n\nRequest path suffix\n^^^^^^^^^^^^^^^^^^^\n\nEach line in the structure must end with the path suffix. You can build\na hierarchical tree by including additional paths that contain common\nparents. Parts of the path that start with a colon ``:`` such as\nitem\\_number in ``/some/:item_number/path`` denote a list and can be\naccessed by an index. For example, you could have a list of cars by\ndefining a structure like this:\n\n.. code:: ini\n\n [Base]\n url = /base/\n\n [Model]\n structure = \n GET,POST cars/\n GET,PUT,DELETE cars/:car_number/\n GET,PUT cars/:car_number/name\n GET,PUT cars/:car_number/make\n GET,PUT cars/:car_number/reg\n\nThe lists are zero-indexed which means to access the make of the 5th car\nstored by your server, you would perform a ``GET`` on:\n\nhttp://127.0.0.1:8080/base/cars/4/make\n\nNotice how ``:car_number`` in the path has been replaced by an index.\n", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/timrainbow/rasblite/archive/1.0.0.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/timrainbow/rasblite", "keywords": "REST,RESTFul,testing,Lightweight,HTTP,server,builder", "license": "MIT License", "maintainer": null, "maintainer_email": null, "name": "rasblite", "package_url": "https://pypi.org/project/rasblite/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/rasblite/", "project_urls": { "Download": "https://github.com/timrainbow/rasblite/archive/1.0.0.tar.gz", "Homepage": "https://github.com/timrainbow/rasblite" }, "release_url": "https://pypi.org/project/rasblite/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Lightweight RESTful API Server Builder", "version": "1.0.0" }, "last_serial": 2923311, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "6e0c80977de415e15e3aa837f439a03e", "sha256": "760f062ee4f790693403f6458be627f10db4e5f15043910a334c08fc8aa56c7e" }, "downloads": -1, "filename": "rasblite-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6e0c80977de415e15e3aa837f439a03e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13367, "upload_time": "2017-06-03T23:26:36", "url": "https://files.pythonhosted.org/packages/f3/2e/2ca3658aabf52a9d41116579bfb239c55f9704110f6a8ace5ef0fe308bfe/rasblite-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6e0c80977de415e15e3aa837f439a03e", "sha256": "760f062ee4f790693403f6458be627f10db4e5f15043910a334c08fc8aa56c7e" }, "downloads": -1, "filename": "rasblite-1.0.0.tar.gz", "has_sig": false, "md5_digest": "6e0c80977de415e15e3aa837f439a03e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13367, "upload_time": "2017-06-03T23:26:36", "url": "https://files.pythonhosted.org/packages/f3/2e/2ca3658aabf52a9d41116579bfb239c55f9704110f6a8ace5ef0fe308bfe/rasblite-1.0.0.tar.gz" } ] }