{ "info": { "author": "Pocheng, Scott", "author_email": "pcghuang@gmail.com, scott820914@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6" ], "description": "# Django REST Framework Google JSON Style API\n\n[![Build Status](https://travis-ci.com/Envive/django-rest-framework-google-json-style-api.svg?branch=master)](https://travis-ci.com/Envive/django-rest-framework-google-json-style-api) \n[![codecov.io](https://codecov.io/github/envive/django-rest-framework-google-json-style-api/coverage.svg?branch=master)](https://codecov.io/github/envive/django-rest-framework-google-json-style-api)\n[![PyPI version](https://badge.fury.io/py/django-rest-framework-google-json-style-api.svg)](https://badge.fury.io/py/django-rest-framework-google-json-style-api)\n\n## Format specification\n- https://google.github.io/styleguide/jsoncstyleguide.xml\n\n## Installation\n\nAt the command line:\n\n```\n$ pip install django-rest-framework-google-json-style-api\n```\n\nAdd the render and parser to your django settings file.\n\n```python\n# ...\nREST_FRAMEWORK = {\n 'PAGE_SIZE': 10,\n 'DEFAULT_PAGINATION_CLASS': \n 'rest_framework_google_json_style_api.pagination.GoogleJsonStylePageNumberPagination',\n 'DEFAULT_RENDERER_CLASSES': (\n 'rest_framework_google_json_style_api.renderers.JSONRenderer',\n # Any other renders\n ),\n 'DEFAULT_PARSER_CLASSES': (\n 'rest_framework_google_json_style_api.parsers.JSONParser',\n # Any other parsers\n ),\n}\n# ...\n```\n\n## Goals\nBy default, Django REST Framework will produce a response like:\n\n```json\n{\n \"id\": 1,\n \"username\": \"scott\",\n \"full_name\": \"Scott Chang\"\n}\n```\n\nand\n\n```json\n[\n {\n \"id\": 1,\n \"username\": \"scott\",\n \"full_name\": \"Scott Chang\"\n },\n {\n \"id\": 2,\n \"username\": \"pocheng\",\n \"full_name\": \"Pocheng Huang\"\n }\n]\n```\n\nGoogle JSON Style Guide shows a response to look like the following:\n\n```json\n{\n \"data\": {\n \"id\": 1,\n \"username\": \"scott\",\n \"fullName\": \"Scott Chang\"\n }\n}\n```\n\nand\n\n```json\n{\n \"data\": {\n \"items\":[\n {\n \"id\": 1,\n \"username\": \"scott\",\n \"fullName\": \"Scott Chang\"\n },\n {\n \"id\": 2,\n \"username\": \"pocheng\",\n \"fullName\": \"Pocheng Huang\"\n }\n ]\n }\n}\n```\n\nGoogle JSON Style Guide uses camel case for field names. So, by default the package uses camel case.\nIf you want to use underscores, you must specify it in your django settings file.\n\n```python\nGOOGLE_JSON_STYLE_API = {\n # ...\n 'CAMELIZE': False\n # ...\n}\n```\n\n## Pagination\n```json\n{\n \"method\": \"list\",\n \"params\": {\n \"page\": \"1\",\n \"pageSize\": \"2\"\n },\n \"data\": {\n \"currentItemCount\": 2,\n \"itemsPerPage\": 2,\n \"totalItems\": 200,\n \"pageIndex\": 1,\n \"totalPages\": 100,\n \"nextLink\": \"http://example.com/api/v1/?page=2&page_size=2\",\n \"previousLink\": null,\n \"items\": [\n {\n \"id\": 1,\n \"username\": \"scott\",\n \"fullName\": \"Scott Chang\"\n },\n {\n \"id\": 2,\n \"username\": \"pocheng\",\n \"fullName\": \"Pocheng Huang\"\n }\n ]\n }\n}\n```\n\n## Attach meta to data object\n\n#### Example\nLet's add the count of items in the data object.\n\n```python\nclass AuthorViewSet(viewsets.ModelViewSet):\n queryset = Author.objects.all()\n # ...\n\n def list(self, request, *args, **kwargs):\n response = super(AuthorViewSet, self).list(request, *args, **kwargs)\n response.data = {\n 'meta': {\n # Add meta data in here\n 'num_items': self.queryset.count(),\n },\n # Keep original data in results\n 'results': response.data\n }\n```\n\n#### Response\n\n```json\n{\n \"data\": {\n \"numItems\": 2,\n \"items\":[\n {\n \"id\": 1,\n \"username\": \"scott\",\n \"fullName\": \"Scott Chang\"\n },\n {\n \"id\": 2,\n \"username\": \"pocheng\",\n \"fullName\": \"Pocheng Huang\"\n }\n ]\n }\n}\n```\n\n\n## Underscoreize Options\nThere are two conventions of snake case.\n\n### Case 1 (default)\n```\nv2Counter -> v_2_counter\nfooBar2 -> foo_bar_2\n```\n\n### Case 2\n```\nv2Counter -> v2_counter\nfooBar2 -> foo_bar2\n```\n\nBy default, the package uses the first case. To use the second case, specify it in your django settings file. The setting only works when you use camel case(default).\n\n```python\nGOOGLE_JSON_STYLE_API = {\n # ...\n 'JSON_UNDERSCOREIZE': {\n 'no_underscore_before_number': True,\n },\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/Envive", "keywords": "", "license": "BSD License", "maintainer": "", "maintainer_email": "", "name": "django-rest-framework-google-json-style-api", "package_url": "https://pypi.org/project/django-rest-framework-google-json-style-api/", "platform": "", "project_url": "https://pypi.org/project/django-rest-framework-google-json-style-api/", "project_urls": { "Homepage": "https://github.com/Envive" }, "release_url": "https://pypi.org/project/django-rest-framework-google-json-style-api/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "Make Google Json Style and Django Rest Framework play nice together.", "version": "1.0.0" }, "last_serial": 5414002, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "25ef5ad7e5565a7f92d436f3ade15437", "sha256": "3712e59c04cee7e87ca6eafc40d3d0208c4aec1269a21a4af7f27bcc6c6fd015" }, "downloads": -1, "filename": "django-rest-framework-google-json-style-api-0.1.1.tar.gz", "has_sig": false, "md5_digest": "25ef5ad7e5565a7f92d436f3ade15437", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10884, "upload_time": "2019-01-25T08:25:17", "url": "https://files.pythonhosted.org/packages/b6/d5/c5a37544e12f9cbbf92efa4546a22b839276ec94aeee228232195a4ea6b8/django-rest-framework-google-json-style-api-0.1.1.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "c4bb4dc9895a796058b862897b5923cf", "sha256": "34b9949ee57fe04bd6e94c29a8aadabf060e487d89e50220de83266708b4e710" }, "downloads": -1, "filename": "django-rest-framework-google-json-style-api-1.0.0.tar.gz", "has_sig": false, "md5_digest": "c4bb4dc9895a796058b862897b5923cf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11689, "upload_time": "2019-06-18T08:42:21", "url": "https://files.pythonhosted.org/packages/39/db/562280637406ca3bb2678210ba05266fbc8b908eda72738bf1ce03b9c00d/django-rest-framework-google-json-style-api-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c4bb4dc9895a796058b862897b5923cf", "sha256": "34b9949ee57fe04bd6e94c29a8aadabf060e487d89e50220de83266708b4e710" }, "downloads": -1, "filename": "django-rest-framework-google-json-style-api-1.0.0.tar.gz", "has_sig": false, "md5_digest": "c4bb4dc9895a796058b862897b5923cf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11689, "upload_time": "2019-06-18T08:42:21", "url": "https://files.pythonhosted.org/packages/39/db/562280637406ca3bb2678210ba05266fbc8b908eda72738bf1ce03b9c00d/django-rest-framework-google-json-style-api-1.0.0.tar.gz" } ] }