{"id":16421839,"url":"https://github.com/aybruhm/api-response","last_synced_at":"2025-09-06T09:32:59.726Z","repository":{"id":53930349,"uuid":"464445026","full_name":"aybruhm/api-response","owner":"aybruhm","description":"A go-to production API response with an easy format for building APIs with Python. 🐍","archived":false,"fork":false,"pushed_at":"2024-05-11T18:12:56.000Z","size":109,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-29T21:11:46.544Z","etag":null,"topics":["api-response","json","python3","rest-api"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/rest-api-response/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aybruhm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-28T10:55:39.000Z","updated_at":"2024-05-11T18:12:59.000Z","dependencies_parsed_at":"2023-02-12T10:46:00.130Z","dependency_job_id":"bf622c26-d58a-4680-a046-1b09eab2676c","html_url":"https://github.com/aybruhm/api-response","commit_stats":null,"previous_names":["aybruhm/api-response","israelabraham/api-payload"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aybruhm%2Fapi-response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aybruhm%2Fapi-response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aybruhm%2Fapi-response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aybruhm%2Fapi-response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aybruhm","download_url":"https://codeload.github.com/aybruhm/api-response/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232110601,"owners_count":18474010,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-response","json","python3","rest-api"],"created_at":"2024-10-11T07:34:57.885Z","updated_at":"2025-01-01T18:05:21.822Z","avatar_url":"https://github.com/aybruhm.png","language":"Python","readme":"# Production API Response\n\n[![Package Code Quality](https://github.com/aybruhm/api-response/actions/workflows/package-test.yml/badge.svg)](https://github.com/aybruhm/api-response/actions/workflows/package-test.yml) [![Package Published to PypI](https://github.com/aybruhm/api-response/actions/workflows/package-publish.yml/badge.svg)](https://github.com/aybruhm/api-response/actions/workflows/package-publish.yml)\n\nA go-to production API response 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-response\n```\n\n2). In the file (.py) that you wish to use it, import it:\n\n```python\nfrom rest_api_response 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 an API class that returns a list of blog posts to a client:\n\n```python\n# imports goes here\n...\nclass PostListAPIView(views.APIView):\n    serializer_class = PostSerializer\n\n    def get(self, request):\n        \"\"\"Returns a list of posts\"\"\"\n\n        posts = Post.objects.all()\n        serializer = self.serializer_class(posts, many=True)\n        return Response(serializer.data)\n```\n\nThe API response 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 response to the next level by doing this:\n\n```python\n# imports goes here\n...\nfrom rest_api_response import success_response\n\n\nclass PostListAPIView(views.APIView):\n    serializer_class = PostSerializer\n\n    def get(self, request):\n        \"\"\"Returns a list of posts\"\"\"\n\n        posts = Post.objects.all()\n        serializer = self.serializer_class(posts, many=True)\n        _response = success_response(\n            message=\"Post retrieved!\",\n            data=serializer.data\n        )\n        return Response(data=_response, status=status.HTTP_200_OK)\n```\n\nThe API response would be:\n\n```json\n[   \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\nAnd that's it. You have a nicely catchy response. :-)\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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faybruhm%2Fapi-response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faybruhm%2Fapi-response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faybruhm%2Fapi-response/lists"}