rest-api-payload


Namerest-api-payload JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://github.com/israelabraham/API-Payload
SummaryA to-go-to production API payload with an easy format for building APIs with Python.
upload_time2023-01-21 14:26:13
maintainer
docs_urlNone
authorAbram
requires_python>=3
licenseMIT
keywords api payload custom api payload
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Production API Payload

A to-go-to production API payload with an easy format for building APIs with Python.

## Quickstart

To get it running, follow the steps below:

1). Pip install the package in your project terminal:

```bash
pip install rest-api-payload
```

2). In the file (.py) that you wish to use it, import it:

```python
    from rest_api_payload import success_response, error_response
```

That's pretty much it - you can now call the function and pass the required arguments!

## Example

Suppose you have a function that returns a response to the client:

```python
...
    def list_of_posts(request):
        """Returns a list of posts"""
        post = Post.objects.all()
        post_serializer = PostSerializer(post, many=True)
        return Response(post_serializer.data)
```

The above response output would be:

```json
    [
        {
            "title": "First blog post", 
            "content": "Lorem ipsume content", 
            "author": 1
        },
        {
            "title": "Second blog post", 
            "content": "Lorem ipsume content", 
            "author": 2
        },
        {
            "title": "Third blog post", 
            "content": "Lorem ipsume content", 
            "author": 3
        }
    ]
```

This works too, but let's take the function to the next level by doing this:

```python
...
from rest_api_payload import success_response


    def list_of_posts(request):
        """Returns a list of post"""
        post = Post.objects.all()
        post_serializer = PostSerializer(post, many=True)

        payload = success_response(
            status=True,
            message="Post retrieved!",
            data=post_serializer.data
        )
        return Response(data=payload, status=status.HTTP_200_OK)
```

The above response output would be:

```json
    [   "status": true, 
        "message":"Posts retrieved!", 
        "data": {
            {
                "title": "First blog post", 
                "content": "Lorem ipsume content", 
                "author": 1
            },
            {
                "title": "Second blog post", 
                "content": "Lorem ipsume content", 
                "author": 2
            },
            {
                "title": "Third blog post", 
                "content": "Lorem ipsume content", 
                "author": 3
            }
        }
    ]
```

*I built this payload because of a project I took lead in building from scratch - and literally had to sympathize with the frontend (web and mobile) engineers. I hope you find this package useful, kindly leave a star if you did.*

## Contribute

All contributions are welcome:

- Read the issues, Fork the project and do a Pull Request.
- Request a new topic creating a `New issue` with the `enhancement` tag.
- Find any kind of errors in the `README` and create a `New issue` with the details or fork the project and do a Pull Request.
- Suggest a better or more pythonic way for existing examples.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/israelabraham/API-Payload",
    "name": "rest-api-payload",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "api,payload,custom api payload",
    "author": "Abram",
    "author_email": "israelvictory87@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b1/f6/2612c6f5e30c9de763b459a9d10b0680a39196b8859a1570d9402fa673d4/rest_api_payload-0.0.7.tar.gz",
    "platform": null,
    "description": "# Production API Payload\n\nA to-go-to production API payload with an easy format for building APIs with Python.\n\n## Quickstart\n\nTo get it running, follow the steps below:\n\n1). Pip install the package in your project terminal:\n\n```bash\npip install rest-api-payload\n```\n\n2). In the file (.py) that you wish to use it, import it:\n\n```python\n    from rest_api_payload import success_response, error_response\n```\n\nThat's pretty much it - you can now call the function and pass the required arguments!\n\n## Example\n\nSuppose you have a function that returns a response to the client:\n\n```python\n...\n    def list_of_posts(request):\n        \"\"\"Returns a list of posts\"\"\"\n        post = Post.objects.all()\n        post_serializer = PostSerializer(post, many=True)\n        return Response(post_serializer.data)\n```\n\nThe above response output would be:\n\n```json\n    [\n        {\n            \"title\": \"First blog post\", \n            \"content\": \"Lorem ipsume content\", \n            \"author\": 1\n        },\n        {\n            \"title\": \"Second blog post\", \n            \"content\": \"Lorem ipsume content\", \n            \"author\": 2\n        },\n        {\n            \"title\": \"Third blog post\", \n            \"content\": \"Lorem ipsume content\", \n            \"author\": 3\n        }\n    ]\n```\n\nThis works too, but let's take the function to the next level by doing this:\n\n```python\n...\nfrom rest_api_payload import success_response\n\n\n    def list_of_posts(request):\n        \"\"\"Returns a list of post\"\"\"\n        post = Post.objects.all()\n        post_serializer = PostSerializer(post, many=True)\n\n        payload = success_response(\n            status=True,\n            message=\"Post retrieved!\",\n            data=post_serializer.data\n        )\n        return Response(data=payload, status=status.HTTP_200_OK)\n```\n\nThe above response output would be:\n\n```json\n    [   \"status\": true, \n        \"message\":\"Posts retrieved!\", \n        \"data\": {\n            {\n                \"title\": \"First blog post\", \n                \"content\": \"Lorem ipsume content\", \n                \"author\": 1\n            },\n            {\n                \"title\": \"Second blog post\", \n                \"content\": \"Lorem ipsume content\", \n                \"author\": 2\n            },\n            {\n                \"title\": \"Third blog post\", \n                \"content\": \"Lorem ipsume content\", \n                \"author\": 3\n            }\n        }\n    ]\n```\n\n*I built this payload because of a project I took lead in building from scratch - and literally had to sympathize with the frontend (web and mobile) engineers. I hope you find this package useful, kindly leave a star if you did.*\n\n## Contribute\n\nAll contributions are welcome:\n\n- Read the issues, Fork the project and do a Pull Request.\n- Request a new topic creating a `New issue` with the `enhancement` tag.\n- Find any kind of errors in the `README` and create a `New issue` with the details or fork the project and do a Pull Request.\n- Suggest a better or more pythonic way for existing examples.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A to-go-to production API payload with an easy format for building APIs with Python.",
    "version": "0.0.7",
    "split_keywords": [
        "api",
        "payload",
        "custom api payload"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "95a2552285cfa68f3bbefcca6a14d1cd55bcacf1b057849d960a982a4a0f93c3",
                "md5": "e250869927a8d5534cd534637a2b3426",
                "sha256": "f726e74949c3010843c3d267a5dae8301e977b583cd7528f40f813e567b0fd95"
            },
            "downloads": -1,
            "filename": "rest_api_payload-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e250869927a8d5534cd534637a2b3426",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3",
            "size": 4377,
            "upload_time": "2023-01-21T14:26:11",
            "upload_time_iso_8601": "2023-01-21T14:26:11.379002Z",
            "url": "https://files.pythonhosted.org/packages/95/a2/552285cfa68f3bbefcca6a14d1cd55bcacf1b057849d960a982a4a0f93c3/rest_api_payload-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b1f62612c6f5e30c9de763b459a9d10b0680a39196b8859a1570d9402fa673d4",
                "md5": "2c221485dd5d068aadeaa6a64ee1d30d",
                "sha256": "6473dbc5cb0187faf8cdbee98b9ecff26ab973baa5e48673449b87107d8291cd"
            },
            "downloads": -1,
            "filename": "rest_api_payload-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "2c221485dd5d068aadeaa6a64ee1d30d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 3962,
            "upload_time": "2023-01-21T14:26:13",
            "upload_time_iso_8601": "2023-01-21T14:26:13.715734Z",
            "url": "https://files.pythonhosted.org/packages/b1/f6/2612c6f5e30c9de763b459a9d10b0680a39196b8859a1570d9402fa673d4/rest_api_payload-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-21 14:26:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "israelabraham",
    "github_project": "API-Payload",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "rest-api-payload"
}
        
Elapsed time: 0.03030s