{ "info": { "author": "Aljosha Friemann", "author_email": "aljosha.friemann@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "simple_rest\n===========\n\nThis is a simple library to build rest clients. It should allow for quick and easy client creation without\noverengineering too much.\n\nExample\n-------\n\nLet's build a simple client. The most complicated part will be writing down the API specification..\nLet's say we define an API via dictionary based on chronos_ to help with the *special needs* of their web interface ::\n\n {\n 'scheduler': {\n 'endpoints': {\n 'jobs': {\n 'methods': {\n 'get': [200]\n }\n },\n 'job': {\n 'endpoints': {\n '$job': {\n 'methods': {\n 'delete': [ 204 ],\n 'put': [ 204 ]\n }\n }\n }\n },\n 'task': {\n 'endpoints': {\n 'kill': {\n 'endpoints': {\n '$task': {\n 'methods': {\n 'delete': [ 204 ]\n }\n }\n }\n }\n }\n },\n 'dependency': {\n 'methods': {\n 'post': [ 204 ]\n }\n },\n 'iso8601': {\n 'methods': {\n 'post': [ 204 ]\n }\n }\n }\n }\n }\n\nAwesome! Now let's put that to use ::\n\n >>> api_definition = { ... } # our dictionary\n\n >>> from simple_rest import API, Client\n\n >>> chronos_api = API(**api_definition)\n >>> chronos_client = Client(host, chronos_api)\n\nCalling an endpoint like *scheduler/jobs* ::\n\n >>> chronos_client.api.scheduler.jobs.get()\n\nWill now request ::\n\n >>> '%s/%s' % (host, 'scheduler/jobs')\n https://10.0.2.121:4400/scheduler/jobs\n\ndue to some funky monkey patching. Take a look at the test module for tipps on how to test requests in your application.\nThe test implemenation is a bit hideous but you'll get the idea.\n\nThe returned object of a request is the default *requests.model.Response*. Due to differences in the REST implementation\nI think it should be up to the user how to handle the response.\n\nFurthermore you might have noticed, for example, the job endpoint labeled '$job' in there. This notation can be used to\nallow variable endpoints. In our case this could be a job id or name ::\n\n >>> baked_endpoint = chronos_client.api.scheduler.job.job('my_job')\n >>> baked_endpoint.get()\n\nAnd the request will go to ::\n\n https://10.0.2.121:4400/scheduler/job/my_job\n\nSome exception behaviour is predefined. Response status codes not given in the specification of an endpoint will result\nin a *RequestStatusException* and a call to http request method (e.g. a *get* to the endpoint *scheduler/dependency*)\nwill raise a *ForbiddenRequestException*. While I believe they are necessary to make errors more obvious, I am not a\n100% happy with them.\n\nNow the only thing left would be to write an abstraction layer for our newly created API ::\n\n >>> import json\n >>> class Chronos(Client):\n ... def __init__(self, host):\n ... super(Chronos, self).__init__(host, chronos_api)\n ...\n ... def list_jobs(self):\n ... return self.api.scheduler.jobs().json()\n\nOf course, while this is a valid approach, I would recommend packaging that in a neat little model. Take a look at my\nother project simple_model_ if you liked this one!\n\n.. _chronos: https://mesos.github.io/chronos/docs/api.html\n.. _simple_model: https://pypi.python.org/pypi/simple_model", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/afriemann/simple_rest.git", "keywords": null, "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "simple_rest", "package_url": "https://pypi.org/project/simple_rest/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/simple_rest/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.org/afriemann/simple_rest.git" }, "release_url": "https://pypi.org/project/simple_rest/0.0.4/", "requires_dist": null, "requires_python": null, "summary": "very simple rest client framework", "version": "0.0.4" }, "last_serial": 1837008, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "813f65f5d58e6f920b8609eb69fb44c0", "sha256": "18bcf0541e5865fd2185ffb1d674b2f2f3e2d0f99c22ce79208535594cb32978" }, "downloads": -1, "filename": "simple_rest-0.0.1.tar.gz", "has_sig": false, "md5_digest": "813f65f5d58e6f920b8609eb69fb44c0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3939, "upload_time": "2015-11-28T02:50:52", "url": "https://files.pythonhosted.org/packages/60/b1/d6475e9f63db9b218c18a88b2d55de140000d80979f53073ee19c8802fb8/simple_rest-0.0.1.tar.gz" } ], "0.0.2": [], "0.0.3": [ { "comment_text": "", "digests": { "md5": "f201d1202d4410f08fd30efb5c3629ed", "sha256": "b61b0475d87bf3d4d8725f3d3f874ef8889c880cd1d9be1fb01b014051a733d5" }, "downloads": -1, "filename": "simple_rest-0.0.3.tar.gz", "has_sig": false, "md5_digest": "f201d1202d4410f08fd30efb5c3629ed", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3987, "upload_time": "2015-11-28T02:59:56", "url": "https://files.pythonhosted.org/packages/5b/1b/55326ea498de882de29ccef25f4a201bd86c9f77974771c56a26ce204817/simple_rest-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "246aebe1733dbbf09d692fd985048989", "sha256": "ef09b0ca0ba9061428bcecfd680dfe1d7ad15cc2e3ce836cdf6fedd59d17b836" }, "downloads": -1, "filename": "simple_rest-0.0.4.tar.gz", "has_sig": false, "md5_digest": "246aebe1733dbbf09d692fd985048989", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3981, "upload_time": "2015-11-28T03:01:50", "url": "https://files.pythonhosted.org/packages/ac/e7/e38b34065140418aeb08607d517f8359be30f65f3bb43542c364d21b0ca8/simple_rest-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "246aebe1733dbbf09d692fd985048989", "sha256": "ef09b0ca0ba9061428bcecfd680dfe1d7ad15cc2e3ce836cdf6fedd59d17b836" }, "downloads": -1, "filename": "simple_rest-0.0.4.tar.gz", "has_sig": false, "md5_digest": "246aebe1733dbbf09d692fd985048989", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3981, "upload_time": "2015-11-28T03:01:50", "url": "https://files.pythonhosted.org/packages/ac/e7/e38b34065140418aeb08607d517f8359be30f65f3bb43542c364d21b0ca8/simple_rest-0.0.4.tar.gz" } ] }