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:
pip install rest-api-payload
2). In the file (.py) that you wish to use it, import it:
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:
...
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:
[
{
"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:
...
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:
[ "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 issuewith theenhancementtag. - Find any kind of errors in the
READMEand create aNew issuewith the details or fork the project and do a Pull Request. - Suggest a better or more pythonic way for existing examples.
Metadata
Release files for rest-api-payload 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| rest_api_payload-0.0.7.tar.gz | 4.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rest_api_payload-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / rest_api_payload-0.0.7.tar.gz
| Download URL | rest_api_payload-0.0.7.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6473dbc5cb0187faf8cdbee98b9ecff26ab973baa5e48673449b87107d8291cd
|
|
BLAKE2b-256 checksum How to use checksums |
b1f62612c6f5e30c9de763b459a9d10b0680a39196b8859a1570d9402fa673d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / rest_api_payload-0.0.7-py3-none-any.whl
| Download URL | rest_api_payload-0.0.7-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f726e74949c3010843c3d267a5dae8301e977b583cd7528f40f813e567b0fd95
|
|
BLAKE2b-256 checksum How to use checksums |
95a2552285cfa68f3bbefcca6a14d1cd55bcacf1b057849d960a982a4a0f93c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for rest-api-payload 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.