{ "info": { "author": "Francesco Zoccheddu", "author_email": "", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7" ], "description": "# Django Simple JSON API\n## Install\n`pip install django-simple-json-api`\n## Instructions\nAdd `dsjapi.decorators.api` or `dsjapi.decorators.api_rq` to your view function. \nReturn a JSON serializable object or a `django.http.HttpResponse` object. \nRaising a `dsjapi.exceptions.ServerException` exception will automatically return the appropriate JSON response.\n### Decorator parameters\n- **`field`** \n `dsjapi.fields.Field` \n Expected field in request body. Default is `None`.\n- **`allowedMethods`** \n `list` of `str` \n Allowed HTTP methods (uppercase). Default is `[\"GET\", \"POST\"]`.\n- **`safeEncoding`** \n `bool` \n `True` to allow non-`dict` response objects. Default is `False`.\n ### `@api` vs `@api_rq`\n- `@api` only provides the validated request data. \n- `@api_rq` provides a `dsjapi.decorators.Request` object that contains both `request` (the original `django.http.HttpRequest` object) and `data` (the validated request data) attributes.\n\n## Examples\n### Views\n```python\nfrom dsjapi.decorators import api\nfrom dsjapi.fields import *\n\n@api (DictField ({\n \"name\": StringField (minLength=2, maxLength=32, regex=r'^[a-zA-Z ]+$'),\n \"bio\": StringField (maxLength=64, missing=Field.Do.DEFAULT, default=\"\"), # Optional (default to \"\")\n \"age\": IntField (min=18, max=130)\n}))\ndef index (data):\n result = putUser (data[\"name\"], data[\"bio\"], data[\"age\"])\n return { \"result\": result }\n```\n```python\nfrom dsjapi.decorators import api\nfrom dsjapi.fields import *\n\n@api (DictField ({\n \"start\": ListField.byLength (2, FloatField ()),\n \"end\": ListField.byLength (2, FloatField (), missing=Field.Do.SKIP), # Optional\n \"time\": FloatField (min=120, max=60*60)\n}))\ndef index (data):\n if \"end\" in data:\n route = getARoute (data[\"start\"], data[\"time\"])\n else:\n route = getABRoute (data[\"start\"], data[\"end\"], data[\"time\"])\n return { \"route\": route }\n```\n```python\nfrom dsjapi.decorators import api\nfrom dsjapi.fields import *\n\n@api (DictField ({\n \"numbers\": ListField.byLength (2, FloatField (min=0))\n}))\ndef index (data):\n sum = 0\n for number in data[\"numbers\"]:\n sum += number\n avg = sum / len (data[\"numbers\"])\n return { \"average\": avg }\n```\n```python\nfrom dsjapi.decorators import api\nfrom dsjapi.fields import *\nfrom dsjapi.exceptions import *\n\n@api (DictField ({\n \"id\": IntField (min=0, max=4096),\n \"password\": StringField (min=8, max=32)\n}))\ndef index (data):\n user = getUserById (data[\"id\"])\n if user is None:\n raise NotFoundException (\"User not found\")\n if user.getPassword () != data[\"password\"]:\n raise AuthenticationException (\"Wrong password\")\n return { \"id\": user.getId (), \"score\": user.getScore () }\n```\n### Custom fields\n```python\nfrom dsjapi.fields import IntField, FieldException\n\nclass EvenNumberField (IntField):\n\n def __init__ (self, min=None, max=None, missing=Field.Do.RAISE, error=Field.Do.RAISE, default=None):\n super ().__init__ (int, min=min, max=max, missing=missing, error=error, default=default)\n\n def clean (self, value):\n value = super ().clean (value)\n if value % 2 != 0:\n raise FieldException (\"Odd number\")\n return value\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/francescozoccheddu/Django-Simple-JSON-API", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-simple-json-api", "package_url": "https://pypi.org/project/django-simple-json-api/", "platform": "", "project_url": "https://pypi.org/project/django-simple-json-api/", "project_urls": { "Homepage": "https://github.com/francescozoccheddu/Django-Simple-JSON-API" }, "release_url": "https://pypi.org/project/django-simple-json-api/0.0.3/", "requires_dist": null, "requires_python": "", "summary": "Create simple JSON APIs with Django", "version": "0.0.3" }, "last_serial": 5372141, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "6e764958b042928fece717f93e9bcf61", "sha256": "3dbc0d837f3e04d98d25a6df5bc7df324483710f956fd088cd63e20c107ed3b6" }, "downloads": -1, "filename": "django-simple-json-api-0.0.1.tar.gz", "has_sig": false, "md5_digest": "6e764958b042928fece717f93e9bcf61", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4325, "upload_time": "2019-06-07T01:11:49", "url": "https://files.pythonhosted.org/packages/6f/0b/a00fb690822b0dc6809fe8835346e2c8aa7a31646ccf8e43b7d628b74a64/django-simple-json-api-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "15ae936a5451a72e0b18d7d447350b84", "sha256": "219e4f8cf9ae2993fb5df2af6c03f5146930d130cae1d98614aa4eaae871c255" }, "downloads": -1, "filename": "django-simple-json-api-0.0.2.tar.gz", "has_sig": false, "md5_digest": "15ae936a5451a72e0b18d7d447350b84", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4638, "upload_time": "2019-06-07T11:56:47", "url": "https://files.pythonhosted.org/packages/a8/e8/28ecadf773ed019ca1c9848de04738dec5f24386df3a1ab6c1db9055d74d/django-simple-json-api-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "66f28af367e63fe5745ba350f9acf7a2", "sha256": "3284d0ee2a6552a150beb8dedabd89b545c9182df6413ca4ed1fcc3894251dfe" }, "downloads": -1, "filename": "django-simple-json-api-0.0.3.tar.gz", "has_sig": false, "md5_digest": "66f28af367e63fe5745ba350f9acf7a2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5435, "upload_time": "2019-06-07T15:52:22", "url": "https://files.pythonhosted.org/packages/fa/cf/603b6f9297ffe721a95470e4bbced95528978724fc1cbd90ff210babd33a/django-simple-json-api-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "66f28af367e63fe5745ba350f9acf7a2", "sha256": "3284d0ee2a6552a150beb8dedabd89b545c9182df6413ca4ed1fcc3894251dfe" }, "downloads": -1, "filename": "django-simple-json-api-0.0.3.tar.gz", "has_sig": false, "md5_digest": "66f28af367e63fe5745ba350f9acf7a2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5435, "upload_time": "2019-06-07T15:52:22", "url": "https://files.pythonhosted.org/packages/fa/cf/603b6f9297ffe721a95470e4bbced95528978724fc1cbd90ff210babd33a/django-simple-json-api-0.0.3.tar.gz" } ] }