{ "info": { "author": "Bharath Kumar Ravichandran", "author_email": "bharathkumarravichandran@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.6" ], "description": "# Responser\n\n[![PRs Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg)](http://makeapullrequest.com) [![made-with-python](https://img.shields.io/badge/made%20with-python-blue.svg)](https://www.python.org/) [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)\n\nResponser is a python package to convert normal strings, objects and other data to REST API response convention and in JSON format.\n\n## Usage\n\n### `Responser`\n-----------------------------------------\n\nResponser is a python package to convert normal strings, objects and other data to REST API response convention and in JSON format.\n\nThis function follows the following JSON structure.\n\n```json\n{\n \"status_code\": 200,\n \"data\": {\n \"name\": \"Bharath Kumar Ravichandran\",\n \"alma_mater\": \"NIT Trichy\",\n \"languages_known\": [\n \"Python\",\n \"PHP\",\n \"JS\",\n \"C++\"\n ],\n \"cool_guy\": \"yes\",\n },\n \"message\": \"OK\"\n}\n```\n\n#### `JSONResponser`\n* Import the function with `from responser import JSONResponser`\n* Definition `JSONResponser(status_code=400, data=None, message=None, strict_mode=false)`\n* The `status_code` can be HTTP status codes or your own custom status codes.\n* If the `status_code` is a HTTP status code and the `data` is `None`, a default\n[reason phrase](https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html) is added. (If `strict_mode` is `False` (default) )\n* If the `status_code` is a HTTP status code and the `message` is `None`, a default\n[reason phrase](https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html) is added. (Even if `strict_mode` is `True` (default) ).\n* If the `status_code` is not a HTTP status code and the `data` is `None`, an empty data is added.\n* If the `status_code` is not a HTTP status code and the `message` is `None`, an empty message is added.\n* If the `strict_mode` is set to `True`, the data given as `data` is encoded.\n* The `status_code` defaults to 400. \n\n**Sample Code**\n```python\nfrom responser import JSONResponser\n\nstatus_code = 200\ndata = {\n \"name\": \"Bharath Kumar Ravichandran\",\n \"alma_mater\": \"NIT Trichy\",\n \"languages_known\": [\n \"Python\",\n \"PHP\",\n \"JS\",\n \"C++\"\n ],\n \"cool_guy\": \"yes\",\n}\nmessage = \"User details returned.\"\n\nresponse = JSONResponser(status_code, data, message)\nprint response\n```\n**Output**\n```json\n{\n \"status_code\": 200,\n \"data\": {\n \"name\": \"Bharath Kumar Ravichandran\",\n \"alma_mater\": \"NIT Trichy\",\n \"languages_known\": [\n \"Python\",\n \"PHP\",\n \"JS\",\n \"C++\"\n ],\n \"cool_guy\": \"yes\",\n },\n \"message\": \"User details returned.\"\n}\n```\n\n\n#### `JSONResponserDecorator`\n* Import the decorator with `from responser import JSONResponserDecorator`\n* Wrap function with decorator `@JSONResponserDecorator`\n* `JSONResponserDecorator` is built on top of JSONResponser, so it follows the same convention as `JSONResponser`.\n\n**Sample Code**\n```python\nfrom responser import JSONResponserDecorator\n\n@JSONResponserDecorator\ndef sample_function():\n\n data = {\n \"name\": \"Bharath Kumar Ravichandran\",\n \"alma_mater\": \"NIT Trichy\",\n \"languages_known\": [\n \"Python\",\n \"PHP\",\n \"JS\",\n \"C++\"\n ],\n \"cool_guy\": \"yes\",\n }\n\n return data\n```\n**Returned Data**\n```json\n{\n \"status_code\": 200,\n \"data\": {\n \"name\": \"Bharath Kumar Ravichandran\",\n \"alma_mater\": \"NIT Trichy\",\n \"languages_known\": [\n \"Python\",\n \"PHP\",\n \"JS\",\n \"C++\"\n ],\n \"cool_guy\": \"yes\",\n },\n \"message\": \"OK\"\n}\n```\n\n\n### Inspired from\n[GokulSrinivas/Sangria](https://github.com/GokulSrinivas/Sangria)\n\n### Contributors\n[Bharath Kumar Ravichandran](https://github.com/BharathKumarRavichandran/)\n\n## License\n[MIT](LICENSE)\n\n![Built with love](http://forthebadge.com/images/badges/built-with-love.svg)\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/BharathKumarRavichandran/responser/", "keywords": "responser json api decorator", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "responser", "package_url": "https://pypi.org/project/responser/", "platform": "", "project_url": "https://pypi.org/project/responser/", "project_urls": { "Homepage": "https://github.com/BharathKumarRavichandran/responser/" }, "release_url": "https://pypi.org/project/responser/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "Responser is a python package to convert normal strings, objects and other data to REST API response convention and in JSON format.", "version": "1.0.0" }, "last_serial": 4814432, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "47562e8122ca678f76bd6272c515aba0", "sha256": "f7af82559dcb9c88bbed2719cfa96eb007cf5cc21236b84ef0122d0b2b4f9874" }, "downloads": -1, "filename": "responser-0.1-py2-none-any.whl", "has_sig": false, "md5_digest": "47562e8122ca678f76bd6272c515aba0", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 4960, "upload_time": "2019-02-12T22:10:43", "url": "https://files.pythonhosted.org/packages/1f/b6/bb20e46a65baf257b946724aa0618322044561516d3ecd5af4e887db57b2/responser-0.1-py2-none-any.whl" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "4883b0c32e311f11a9f6ead178fbd55d", "sha256": "b853f28953b94e9dd2f3833acfa0ac82212dae554d5adf6be670925f63a59722" }, "downloads": -1, "filename": "responser-1.0.0-py2-none-any.whl", "has_sig": false, "md5_digest": "4883b0c32e311f11a9f6ead178fbd55d", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 4913, "upload_time": "2019-02-13T07:19:10", "url": "https://files.pythonhosted.org/packages/e3/fc/3a191c4ff5d5ff416097c1b882b30c5b50503cb4c06fd40e84765b5688ba/responser-1.0.0-py2-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4883b0c32e311f11a9f6ead178fbd55d", "sha256": "b853f28953b94e9dd2f3833acfa0ac82212dae554d5adf6be670925f63a59722" }, "downloads": -1, "filename": "responser-1.0.0-py2-none-any.whl", "has_sig": false, "md5_digest": "4883b0c32e311f11a9f6ead178fbd55d", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 4913, "upload_time": "2019-02-13T07:19:10", "url": "https://files.pythonhosted.org/packages/e3/fc/3a191c4ff5d5ff416097c1b882b30c5b50503cb4c06fd40e84765b5688ba/responser-1.0.0-py2-none-any.whl" } ] }