{"id":29100427,"url":"https://github.com/yosef-alsabbah/drf-standardized-responses","last_synced_at":"2026-04-24T20:31:46.321Z","repository":{"id":300757137,"uuid":"1007059834","full_name":"Yosef-AlSabbah/drf-standardized-responses","owner":"Yosef-AlSabbah","description":"A Django app for Django REST Framework that provides consistent, standardized API responses, pagination, and error handling out of the box — ensuring predictable and clean JSON across your API.","archived":false,"fork":false,"pushed_at":"2025-06-24T11:45:24.000Z","size":30,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-20T18:00:23.050Z","etag":null,"topics":["django","drf","error-handling","json-api","pagination","renderer","response","standardized-responses"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Yosef-AlSabbah.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2025-06-23T12:00:10.000Z","updated_at":"2025-12-20T15:58:24.000Z","dependencies_parsed_at":"2025-06-23T13:02:33.424Z","dependency_job_id":"5e4930dd-9c4e-4622-a84c-2fd92d7d2240","html_url":"https://github.com/Yosef-AlSabbah/drf-standardized-responses","commit_stats":null,"previous_names":["yosef-alsabbah/drf-standardized-responses"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Yosef-AlSabbah/drf-standardized-responses","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yosef-AlSabbah%2Fdrf-standardized-responses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yosef-AlSabbah%2Fdrf-standardized-responses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yosef-AlSabbah%2Fdrf-standardized-responses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yosef-AlSabbah%2Fdrf-standardized-responses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yosef-AlSabbah","download_url":"https://codeload.github.com/Yosef-AlSabbah/drf-standardized-responses/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yosef-AlSabbah%2Fdrf-standardized-responses/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32239463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["django","drf","error-handling","json-api","pagination","renderer","response","standardized-responses"],"created_at":"2025-06-28T18:13:40.971Z","updated_at":"2026-04-24T20:31:46.316Z","avatar_url":"https://github.com/Yosef-AlSabbah.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# drf-standardized-responses\n\n[![PyPI](https://img.shields.io/pypi/v/drf-standardized-responses.svg)](https://pypi.org/project/drf-standardized-responses/)\n[![CI/CD](https://github.com/Yosef-AlSabbah/drf-standardized-responses/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/Yosef-AlSabbah/drf-standardized-responses/actions/workflows/ci-cd.yml)\n[![PyPI Downloads](https://static.pepy.tech/badge/drf-standardized-responses)](https://pepy.tech/projects/drf-standardized-responses)\n[![Python Version](https://img.shields.io/pypi/pyversions/drf-standardized-responses.svg)](https://pypi.org/project/drf-standardized-responses/)\n[![License](https://img.shields.io/badge/license-BSD-blue.svg)](LICENSE)\n\nA Django REST Framework utility for standardized API responses, pagination, and exception handling.\n\n---\n\n## Features\n\n- **Consistent Response Format**: All API responses follow a standardized structure (`success`, `message`, `data`, with optional `meta` and `errors` fields).\n- **Custom Renderer**: A `StandardResponseRenderer` that formats all responses consistently, preventing common issues like double-wrapping.\n- **Standardized Pagination**: `StandardPagination` class that provides rich metadata, including `count`, `total_pages`, and `current_page`.\n- **Custom Exception Handler**: A handler that catches DRF exceptions and formats them into the standard error response structure.\n- **Helper Functions**: Utilities to easily create standardized success and error responses.\n\n---\n\n## Standard Response Structure\n\n### Success Response\n\n```json\n{\n  \"success\": true,\n  \"message\": \"Operation successful\",\n  \"data\": {\n    \"id\": 1,\n    \"name\": \"Item 1\"\n  }\n}\n```\n\n### Success Response with Pagination\n\n```json\n{\n  \"success\": true,\n  \"message\": \"Operation successful\",\n  \"data\": [\n    {\n      \"id\": 1,\n      \"name\": \"Item 1\"\n    }\n  ],\n  \"meta\": {\n    \"pagination\": {\n      \"count\": 100,\n      \"next\": \"http://api.example.org/items?page=2\",\n      \"previous\": null,\n      \"total_pages\": 10,\n      \"current_page\": 1,\n      \"page_size\": 10\n    }\n  }\n}\n```\n\n### Error Response\n\n```json\n{\n  \"success\": false,\n  \"message\": \"Validation failed\",\n  \"data\": {},\n  \"errors\": {\n    \"name\": [\"This field is required\"],\n    \"email\": [\"Enter a valid email address\"]\n  }\n}\n```\n\n---\n\n## Installation\n\n```bash\npip install drf-standardized-responses\n```\n\n---\n\n## Quick Start\n\nAdd the following to your Django `settings.py`:\n\n```python\nREST_FRAMEWORK = {\n    # Use the custom exception handler\n    'EXCEPTION_HANDLER': 'drf_standardized_responses.exceptions.standardized_exception_handler',\n\n    # Use the custom pagination class\n    'DEFAULT_PAGINATION_CLASS': 'drf_standardized_responses.pagination.StandardPagination',\n\n    # Use the custom renderer\n    'DEFAULT_RENDERER_CLASSES': [\n        'drf_standardized_responses.renderers.StandardResponseRenderer',\n        # Add other renderers if needed, like BrowsableAPIRenderer\n        'rest_framework.renderers.BrowsableAPIRenderer',\n    ],\n}\n```\n\n---\n\n## API Reference\n\n### `StandardResponse`\n\nA utility class for creating standardized API responses.\n\n```python\nfrom drf_standardized_responses.responses import StandardResponse\n\n# Create a success response\nresponse = StandardResponse.success(\n    data={\"key\": \"value\"},\n    message=\"Data retrieved successfully\",\n    meta={\"custom_meta\": \"value\"},\n    status_code=200\n)\n\n# Create an error response\nresponse = StandardResponse.error(\n    message=\"Validation failed\",\n    errors={\"field\": [\"This field is required\"]},\n    status_code=400\n)\n```\n\n### `StandardResponseRenderer`\n\nThis renderer automatically wraps your API responses in the standard structure. It correctly handles both error and success responses.\n\n### `StandardPagination`\n\nA pagination class that integrates with the standardized response format to provide consistent pagination metadata.\n\n### `standardized_exception_handler`\n\nAn exception handler that catches DRF exceptions and formats them into standardized error responses.\n\n## Testing\n\nRun the test suite:\n\n```bash\npytest\n```\n\n---\n\n## Author\n\n- Yousef M. Y. Al Sabbah \u003citzyousefalsabbah@gmail.com\u003e\n- GitHub: [Yosef-AlSabbah](https://github.com/Yosef-AlSabbah)\n\n---\n\n## Contributing\n\nContributions are welcome! Please check out the [contributing guidelines](CONTRIBUTING.md) for more details on how to contribute to this project.\n\n---\n\n## License\n\nBSD-3-Clause\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyosef-alsabbah%2Fdrf-standardized-responses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyosef-alsabbah%2Fdrf-standardized-responses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyosef-alsabbah%2Fdrf-standardized-responses/lists"}