Skip to content

Commit b37bb40

Browse files
committed
Build new dist directory
1 parent f99979f commit b37bb40

File tree

5 files changed

+130
-0
lines changed

5 files changed

+130
-0
lines changed

dist/rest_api_payload-0.0.1.tar.gz

3.18 KB
Binary file not shown.

rest_api_payload.egg-info/PKG-INFO

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
Metadata-Version: 2.1
2+
Name: rest-api-payload
3+
Version: 0.0.1
4+
Summary: Industry ready custom API payload with an easy format for building Python APIs (Django/Django Rest Framework)
5+
Home-page: https://github.com/israelabraham
6+
Author: Abraham (Abram 🐼) Israel
7+
Author-email: [email protected]
8+
License: MIT
9+
Description: Industry ready custom API payload with an easy format for building Python APIs (Django/Django Rest Framework)
10+
11+
Yosh! If you are a django backend developer and have used the amazing utility toolkit for creating amazing APIs. You probably have come across the way django rest framework lets you return data by default. Not industry standard, if I may add.
12+
13+
So you serialize what object you want, and it serialized and you return it like so;
14+
15+
```
16+
class GetPostsAPiView(APIView):
17+
18+
def get(self, request):
19+
posts = Post.objects.all()
20+
post_serializer = PostSerializer(posts, many=True)
21+
22+
if post_serializer.is_valid():
23+
post_serializer.save()
24+
return Response(serializer.data)
25+
26+
else:
27+
return Response(serializer.errors)
28+
29+
30+
# OUTPUT
31+
-----------
32+
- success response
33+
{
34+
'title': 'First blog post',
35+
'content': 'Lorem ipsume content',
36+
'author': 1
37+
}
38+
39+
- error response
40+
{
41+
['title']: 'field is required'
42+
}
43+
44+
```
45+
46+
Does the above ouput makes sense to you? I mean, it clearly doesn't help the frontend devs, trying putting yourself in their shoes. Imagine the dev is trying to check for the status code in the data been outputted, and the above is what the developer got. Dang! Extra work, right? I happen to work with a mobile developer, and he changed the way I build APIs. So instead of the above way, what do you think of this;
47+
48+
```
49+
from module import success_response, error_response
50+
51+
52+
class GetPostsAPiView(APIView):
53+
54+
def get(self, request):
55+
posts = Post.objects.all()
56+
post_serializer = PostSerializer(posts, many=True)
57+
58+
if post_serializer.is_valid():
59+
post_serializer.save()
60+
61+
payload = success_response(
62+
status="200 ok",
63+
message="All the posts don come, chief!"
64+
data=serializer.data
65+
)
66+
return Response(data=payload)
67+
68+
else:
69+
payload = error_response(
70+
status="400 bad request",
71+
message="Something went wrong, chief! Try again sometime"
72+
)
73+
return Response(data=payload)
74+
75+
76+
# OUTPUT
77+
-----------
78+
- success response
79+
{
80+
'status': '200 ok',
81+
'message':'All the posts don come, chief!',
82+
'data': {'title': 'First blog post', 'content': 'Lorem ipsume content', 'author': 1}'
83+
}
84+
85+
- error response
86+
{
87+
'status': '400 bad request',
88+
'message': 'Ahh, chief, nothing dey here oooo!',
89+
'data': {['title']: 'field is required'}
90+
}
91+
92+
```
93+
94+
What do you think about the above? Pretty neat and industry standard, right? Installing the package is pretty is easy, fam. Here's how to:
95+
96+
> pip install module
97+
98+
In the file (.py) that you wish to use it, import it. <br>
99+
100+
> from module import success_response, error_response
101+
102+
And that's all, you can begin calling the function and passing arguments!
103+
104+
<br>
105+
106+
## Contribute
107+
108+
All contributions are welcome:
109+
110+
- Read the issues, Fork the project and do a Pull Request.
111+
- Request a new topic creating a `New issue` with the `enhancement` tag.
112+
- 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.
113+
- Suggest a better or more pythonic way for existing examples.
114+
Keywords: api,payload,custom api payload
115+
Platform: UNKNOWN
116+
Classifier: Development Status :: 5 - Production/Stable
117+
Classifier: Intended Audience :: Education
118+
Classifier: Intended Audience :: Developers
119+
Classifier: License :: OSI Approved :: MIT License
120+
Classifier: Programming Language :: Python :: 3
121+
Description-Content-Type: text/markdown

rest_api_payload.egg-info/SOURCES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
README.md
2+
setup.py
3+
rest_api_payload/__init__.py
4+
rest_api_payload.egg-info/PKG-INFO
5+
rest_api_payload.egg-info/SOURCES.txt
6+
rest_api_payload.egg-info/dependency_links.txt
7+
rest_api_payload.egg-info/top_level.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rest_api_payload

0 commit comments

Comments
 (0)