Skip to main content

DRF middleware to wrap all API responses

Project description

DRF Response Wrapper

A Django REST Framework middleware that automatically wraps all API responses into a consistent format.
No need to modify your views or APIView classes.


🚀 Features

  • Standardized success & error responses
  • Works with all DRF APIViews
  • Simple integration: just add middleware
  • No changes needed in your views

📦 Installation

Install the package from PyPI:

pip install drf-response-wrapper

⚙️ Usage / User Guide

1️⃣ Add Middleware

Open your Django project's settings.py and add the middleware:

MIDDLEWARE = [
    # Other middlewares
    "drf_response_wrapper.middleware.APIResponseWrapperMiddleware",
]

This middleware automatically wraps all DRF API responses, so you don't need to manually call success_response() or error_response() in your views.


2️⃣ Example API Responses

Success response example:

{
  "success": true,
  "message": "Request successful",
  "status": 200,
  "data": {
    "id": 1,
    "name": "Example Item"
  }
}

Error response example:

{
  "success": false,
  "message": "Something went wrong",
  "status": 400,
  "data": {}
}

3️⃣ Notes / Tips

  • Works with any DRF APIView returning Response.
  • Can be used with BaseAPIView or standard APIView.
  • Ensures all API responses follow the same structure automatically.
  • No changes needed in your existing views.
  • Compatible with existing DRF projects—just add middleware.
  • Ideal for projects where consistent API response format is required.

📝 License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drf_response_wrappers-1.2.6.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drf_response_wrappers-1.2.6-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file drf_response_wrappers-1.2.6.tar.gz.

File metadata

  • Download URL: drf_response_wrappers-1.2.6.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for drf_response_wrappers-1.2.6.tar.gz
Algorithm Hash digest
SHA256 fdca86a2d53ea107446f5c9f5d186fdf1cc437152831db054f0445fa41cd1b32
MD5 d1e33ff7b6d18e3f1d3109ca111ba534
BLAKE2b-256 a8c50a5c9d9d707801d1640a48481df2d1821b19ddb19ae3688b231e634c045f

See more details on using hashes here.

File details

Details for the file drf_response_wrappers-1.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_response_wrappers-1.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 438a8d3acbce2ae96b4bcec51bd3db3660f1936fe074ef227108b3eb81af0b00
MD5 bd01cb8d676f472ae5272f8346e1cf35
BLAKE2b-256 2b5c5992a82eed356752b7fb3b9d0c4f2f7a193b66f1e3b4149240249f2fb43a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page