drf-json-api-utils


Namedrf-json-api-utils JSON
Version 2.0.78 PyPI version JSON
download
home_pagehttps://github.com/amitassaraf/drf-json-api-utils
SummaryUtilities to reduce the boiler-plating of django-rest-framework-json-api
upload_time2023-01-22 19:39:44
maintainer
docs_urlNone
authorAmit Assaraf
requires_python>=3.5
license
keywords setuptools development
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # DRF Json Api Utils

Utilities to massivly reduce the boiler-plating of [django-rest-framework][drf].

This project currenly only supports and is specific to [django-rest-framework-json-api][drfjapi], if requested will extend it to general  [django-rest-framework][drf] support.

[The source for this project is available here][src].

- [ ] Add better docs.

Example Usage
----

By just doing this:

```python
user_urls = JsonApiViewBuilder(model=MyUser, 
                               resource_name='users',
                               allowed_methods=[json_api_spec_http_methods.HTTP_GET]) \
.fields(['email', 'first_name', 'last_name']) \
.add_filter(name='email', lookups=(lookups.EXACT, lookups.IN)) \
.add_filter(name='order', field='orders__id', lookups=(lookups.EXACT, lookups.IN)) \
.add_relation(field='orders', many=True) \
.get_urls()

order_urls = JsonApiViewBuilder(model=Order, 
                               resource_name='orders',
                               allowed_methods=[json_api_spec_http_methods.HTTP_GET]) \
.fields(['product', 'date', 'price']) \
.add_relation(field='user', resource_name='users') \
.get_urls()
```

You can get this:

`GET /api/users?filter[email]=amit.assaraf@gmail.com`
```json
{
    "links": {
        "first": "http://localhost:8000/api/users?filter%5Bemail%5D=soit48%40gmail.com&page%5Bnumber%5D=1",
        "last": "http://localhost:8000/api/users?filter%5Bemail%5D=soit48%40gmail.com&page%5Bnumber%5D=1",
        "next": null,
        "prev": null
    },
    "data": [
        {
            "type": "users",
            "id": "76f7c463-b6a8-4b20-917a-ef98c546eec4",
            "attributes": {
                "first-name": "Amit",
                "last-name": "Assaraf",
                "email": "amit.assaraf@gmail.com",
            },
            "relationships": {
                "orders": {
                    "meta": {
                        "count": 2
                    },
                    "data": [
                        {
                            "type": "orders",
                            "id": "6b99e044-462f-472e-9fed-307436b73549"
                        },
                        {
                            "type": "orders",
                            "id": "304f7f60-7e24-494e-98e2-e9786a3eb588"
                        }
                    ],
                    "links": {
                        "self": "http://localhost:8000/api/users/76f7c463-b6a8-4b20-917a-ef98c546eec4/relationships/orders",
                        "related": "http://localhost:8000/api/orders/76f7c463-b6a8-4b20-917a-ef98c546eec4/"
                    }
                }
            }
        }
    ],
    "meta": {
        "pagination": {
            "page": 1,
            "pages": 1,
            "count": 1
        }
    }
}
```

[src]: https://github.com/amitassaraf/drf-json-api-utils
[drfjapi]: https://github.com/django-json-api/django-rest-framework-json-api
[drf]: https://www.django-rest-framework.org/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/amitassaraf/drf-json-api-utils",
    "name": "drf-json-api-utils",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "setuptools development",
    "author": "Amit Assaraf",
    "author_email": "amit.assaraf@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e7/3e/63c6aec455be666f2d3c514cf82ec12cd1070e60915bb59713256b721e1c/drf-json-api-utils-2.0.78.tar.gz",
    "platform": null,
    "description": "# DRF Json Api Utils\n\nUtilities to massivly reduce the boiler-plating of [django-rest-framework][drf].\n\nThis project currenly only supports and is specific to [django-rest-framework-json-api][drfjapi], if requested will extend it to general  [django-rest-framework][drf] support.\n\n[The source for this project is available here][src].\n\n- [ ] Add better docs.\n\nExample Usage\n----\n\nBy just doing this:\n\n```python\nuser_urls = JsonApiViewBuilder(model=MyUser, \n                               resource_name='users',\n                               allowed_methods=[json_api_spec_http_methods.HTTP_GET]) \\\n.fields(['email', 'first_name', 'last_name']) \\\n.add_filter(name='email', lookups=(lookups.EXACT, lookups.IN)) \\\n.add_filter(name='order', field='orders__id', lookups=(lookups.EXACT, lookups.IN)) \\\n.add_relation(field='orders', many=True) \\\n.get_urls()\n\norder_urls = JsonApiViewBuilder(model=Order, \n                               resource_name='orders',\n                               allowed_methods=[json_api_spec_http_methods.HTTP_GET]) \\\n.fields(['product', 'date', 'price']) \\\n.add_relation(field='user', resource_name='users') \\\n.get_urls()\n```\n\nYou can get this:\n\n`GET /api/users?filter[email]=amit.assaraf@gmail.com`\n```json\n{\n    \"links\": {\n        \"first\": \"http://localhost:8000/api/users?filter%5Bemail%5D=soit48%40gmail.com&page%5Bnumber%5D=1\",\n        \"last\": \"http://localhost:8000/api/users?filter%5Bemail%5D=soit48%40gmail.com&page%5Bnumber%5D=1\",\n        \"next\": null,\n        \"prev\": null\n    },\n    \"data\": [\n        {\n            \"type\": \"users\",\n            \"id\": \"76f7c463-b6a8-4b20-917a-ef98c546eec4\",\n            \"attributes\": {\n                \"first-name\": \"Amit\",\n                \"last-name\": \"Assaraf\",\n                \"email\": \"amit.assaraf@gmail.com\",\n            },\n            \"relationships\": {\n                \"orders\": {\n                    \"meta\": {\n                        \"count\": 2\n                    },\n                    \"data\": [\n                        {\n                            \"type\": \"orders\",\n                            \"id\": \"6b99e044-462f-472e-9fed-307436b73549\"\n                        },\n                        {\n                            \"type\": \"orders\",\n                            \"id\": \"304f7f60-7e24-494e-98e2-e9786a3eb588\"\n                        }\n                    ],\n                    \"links\": {\n                        \"self\": \"http://localhost:8000/api/users/76f7c463-b6a8-4b20-917a-ef98c546eec4/relationships/orders\",\n                        \"related\": \"http://localhost:8000/api/orders/76f7c463-b6a8-4b20-917a-ef98c546eec4/\"\n                    }\n                }\n            }\n        }\n    ],\n    \"meta\": {\n        \"pagination\": {\n            \"page\": 1,\n            \"pages\": 1,\n            \"count\": 1\n        }\n    }\n}\n```\n\n[src]: https://github.com/amitassaraf/drf-json-api-utils\n[drfjapi]: https://github.com/django-json-api/django-rest-framework-json-api\n[drf]: https://www.django-rest-framework.org/\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Utilities to reduce the boiler-plating of django-rest-framework-json-api",
    "version": "2.0.78",
    "split_keywords": [
        "setuptools",
        "development"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e73e63c6aec455be666f2d3c514cf82ec12cd1070e60915bb59713256b721e1c",
                "md5": "5fa7d5cfc467cb1d0c9b449e7ebc3fbd",
                "sha256": "79e6f4d4395088846be19ac611805721c0dcb5cf8320c25ab41384f45bcad531"
            },
            "downloads": -1,
            "filename": "drf-json-api-utils-2.0.78.tar.gz",
            "has_sig": false,
            "md5_digest": "5fa7d5cfc467cb1d0c9b449e7ebc3fbd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 29201,
            "upload_time": "2023-01-22T19:39:44",
            "upload_time_iso_8601": "2023-01-22T19:39:44.053042Z",
            "url": "https://files.pythonhosted.org/packages/e7/3e/63c6aec455be666f2d3c514cf82ec12cd1070e60915bb59713256b721e1c/drf-json-api-utils-2.0.78.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-22 19:39:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "amitassaraf",
    "github_project": "drf-json-api-utils",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "drf-json-api-utils"
}
        
Elapsed time: 0.03573s