Skip to content

Commit

Permalink
Modified .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
aybruhm committed Mar 1, 2022
1 parent dd928eb commit bbafa72
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/
dist/
dist/
__pycache__
123 changes: 123 additions & 0 deletions rest_api_payload.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
Metadata-Version: 2.1
Name: rest-api-payload
Version: 0.0.4
Summary: Industry ready custom API payload with an easy format for building Python APIs (Django/Django Rest Framework)
Home-page: https://github.com/israelabraham/API-Payload
Author: Abram 🐼
Author-email: israelvictory87@gmail.com
License: MIT
Project-URL: Bug Tracker, https://github.com/israelabraham/API-Payload/issues
Description: Industry ready custom API payload with an easy format for building Python APIs (Django/Django Rest Framework)

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.

So you serialize what object you want, and it serialized and you return it like so;

```
class GetPostsAPiView(APIView):

def get(self, request):
posts = Post.objects.all()
post_serializer = PostSerializer(posts, many=True)

if post_serializer.is_valid():
post_serializer.save()
return Response(serializer.data)

else:
return Response(serializer.errors)


# OUTPUT
-----------
- success response
{
'title': 'First blog post',
'content': 'Lorem ipsume content',
'author': 1
}

- error response
{
['title']: 'field is required'
}

```

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;

```
from module import success_response, error_response


class GetPostsAPiView(APIView):

def get(self, request):
posts = Post.objects.all()
post_serializer = PostSerializer(posts, many=True)

if post_serializer.is_valid():
post_serializer.save()

payload = success_response(
status="200 ok",
message="All the posts don come, chief!"
data=serializer.data
)
return Response(data=payload)

else:
payload = error_response(
status="400 bad request",
message="Something went wrong, chief! Try again sometime"
)
return Response(data=payload)


# OUTPUT
-----------
- success response
{
'status': '200 ok',
'message':'All the posts don come, chief!',
'data': {'title': 'First blog post', 'content': 'Lorem ipsume content', 'author': 1}'
}

- error response
{
'status': '400 bad request',
'message': 'Ahh, chief, nothing dey here oooo!',
'data': {['title']: 'field is required'}
}

```

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:

> pip install rest-api-payload

In the file (.py) that you wish to use it, import it. <br>

> from rest_api_payload import success_response, error_response

And that's all, you can begin calling the function and passing arguments!

<br>

## 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.
Keywords: api,payload,custom api payload
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3
Description-Content-Type: text/markdown
9 changes: 9 additions & 0 deletions rest_api_payload.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
README.md
pyproject.toml
setup.cfg
setup.py
rest_api_payload/__init__.py
rest_api_payload.egg-info/PKG-INFO
rest_api_payload.egg-info/SOURCES.txt
rest_api_payload.egg-info/dependency_links.txt
rest_api_payload.egg-info/top_level.txt
1 change: 1 addition & 0 deletions rest_api_payload.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions rest_api_payload.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rest_api_payload

0 comments on commit bbafa72

Please sign in to comment.