Provides views to redirect incoming request to another API server.
- Masquerade paths
- HTTP Basic Auth (between your API and backend API)
- Token Auth
- Supported methods: GET/POST/PUT/PATCH/DELETE
- File uploads
- Django 4.2 LTS support
- Python 3.9+ support
| Version | Django Support | Python Support | Status |
|---|---|---|---|
| 2.x | 3.2, 4.0, 4.1, 4.2 LTS | 3.9, 3.10, 3.11, 3.12 | ✅ Active |
| 1.x | 2.2, 3.0, 3.1, 3.2 | 3.8+ | 🔒 Maintenance only |
poetry add ws-django-rest-framework-proxyor
pip install ws-django-rest-framework-proxyAdd to your INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'rest_framework',
'rest_framework_proxy',
# ...
]Configure proxy settings:
# settings.py
REST_PROXY = {
'HOST': 'https://api.example.com',
'AUTH': {
'user': 'myuser',
'password': 'mypassword',
# Or alternatively:
'token': 'Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b',
},
'TIMEOUT': 30,
'VERIFY_SSL': True,
}# urls.py
from django.urls import path
from rest_framework_proxy.views import ProxyView
urlpatterns = [
# Basic proxy
path('api/items/', ProxyView.as_view(source='items/'), name='item-list'),
# With URL parameters
path('api/items/<int:pk>/', ProxyView.as_view(source='items/%(pk)s/'), name='item-detail'),
]# views.py
from rest_framework_proxy.views import ProxyView
class ItemListProxy(ProxyView):
"""
Proxy for item list API
"""
source = 'items/'
class ItemDetailProxy(ProxyView):
"""
Proxy for item detail API
"""
source = 'items/%(pk)s/'git clone https://github.com/driveate/ws-django-rest-framework-proxy.git
cd ws-django-rest-framework-proxy
poetry install# Run all tests
poetry run python -m django test tests --settings=tests.settings
# Run with coverage
poetry run pytest --cov=rest_framework_proxy
# Run linting
poetry run flake8 rest_framework_proxy/
poetry run black --check rest_framework_proxy/
poetry run mypy rest_framework_proxy/poetry run toxVersion 2.0 introduces breaking changes for Django 4.2 compatibility:
- Python 3.9+ Required: Dropped support for Python 3.8
- Django 3.2+ Required: Dropped support for Django 2.x and 3.0/3.1
- Removed six dependency: No longer needed for Python 3.9+
- Update your Python version to 3.9 or higher
- Update Django to 3.2 or higher
- Update the package:
poetry add ws-django-rest-framework-proxy@^2.0.0 - Test your proxy views thoroughly
No code changes should be required in most cases, as the API remains the same.
Copyright (c) 2014, Tomi Pajunen All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.