{"id":13813579,"url":"https://github.com/eofs/django-rest-framework-proxy","last_synced_at":"2025-05-15T00:33:36.014Z","repository":{"id":6667394,"uuid":"7912139","full_name":"eofs/django-rest-framework-proxy","owner":"eofs","description":"Django Rest Framework Proxy views","archived":false,"fork":false,"pushed_at":"2020-03-04T09:33:33.000Z","size":70,"stargazers_count":138,"open_issues_count":17,"forks_count":58,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-07T21:08:04.691Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eofs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-30T10:06:16.000Z","updated_at":"2024-08-02T06:00:28.000Z","dependencies_parsed_at":"2022-08-28T02:53:45.186Z","dependency_job_id":null,"html_url":"https://github.com/eofs/django-rest-framework-proxy","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eofs%2Fdjango-rest-framework-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eofs%2Fdjango-rest-framework-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eofs%2Fdjango-rest-framework-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eofs%2Fdjango-rest-framework-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eofs","download_url":"https://codeload.github.com/eofs/django-rest-framework-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225319275,"owners_count":17455739,"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":[],"created_at":"2024-08-04T04:01:22.022Z","updated_at":"2024-11-19T08:30:46.392Z","avatar_url":"https://github.com/eofs.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"Django Rest Framework Proxy\n====================\n\n[![PyPI version](https://badge.fury.io/py/django-rest-framework-proxy.svg)](http://badge.fury.io/py/django-rest-framework-proxy)\n[![Build Status](https://travis-ci.org/eofs/django-rest-framework-proxy.svg?branch=master)](https://travis-ci.org/eofs/django-rest-framework-proxy)\n[![Coverage Status](https://coveralls.io/repos/eofs/django-rest-framework-proxy/badge.png?branch=master)](https://coveralls.io/r/eofs/django-rest-framework-proxy?branch=master)\n\nProvides views to redirect incoming request to another API server.\n\n**Features:**\n\n* Masquerade paths\n* HTTP Basic Auth (between your API and backend API)\n* Token Auth\n* Supported methods: GET/POST/PUT/PATCH\n* File uploads\n\n**TODO:**\n* Pass auth information from original client to backend API\n\n#Installation#\n\n```bash\n$ pip install django-rest-framework-proxy\n```\n\n#Usage#\nThere are couple of ways to use proxies. You can either use provided views as is or subclass them.\n\n## Settings ##\n```python\n# settings.py\nREST_PROXY = {\n    'HOST': 'https://api.example.com',\n    'AUTH': {\n        'user': 'myuser',\n        'password': 'mypassword',\n        # Or alternatively:\n        'token': 'Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b',\n    },\n}\n```\n\n\n## Simple way ##\n```python\n# urls.py\nfrom rest_framework_proxy.views import ProxyView\n\n# Basic\nurl(r'^item/$', ProxyView.as_view(source='items/'), name='item-list'),\n\n# With captured URL parameters\nurl(r'^item/(?P\u003cpk\u003e[0-9]+)$', ProxyView.as_view(source='items/%(pk)s'), name='item-detail'),\n```\n## Complex way ##\n```python\n# views.py\nfrom rest_framework_proxy.views import ProxyView\n\nclass ItemListProxy(ProxyView):\n  \"\"\"\n  List of items\n  \"\"\"\n  source = 'items/'\n\nclass ItemDetailProxy(ProxyView):\n  \"\"\"\n  Item detail\n  \"\"\"\n  source = 'items/%(pk)s'\n\n```\n```python\n# urls.py\nfrom views import ProxyListView, ProxyDetailView\n\nurl(r'^item/$', ProxyListView.as_view(), name='item-list'),\nurl(r'^item/(?P\u003cpk\u003e[0-9]+)$', ProxyDetailView.as_view(), name='item-detail'),\n```\n\n# Settings #\n\u003ctable\u003e\n    \u003cthead\u003e\n        \u003ctr\u003e\n            \u003ctd\u003eSetting\u003c/td\u003e\n            \u003ctd\u003eDefault\u003c/td\u003e\n            \u003ctd\u003eComment\u003c/td\u003e\n        \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n        \u003ctr\u003e\n            \u003ctd\u003eHOST\u003c/td\u003e\n            \u003ctd\u003e\u003ccode\u003eNone\u003c/code\u003e\u003c/td\u003e\n            \u003ctd\u003eProxy request to this host (e.g. https://example.com/api/).\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003eAUTH\u003c/td\u003e\n            \u003ctd\u003e\u003ccode\u003e{'user': None, 'password': None, 'token': None}\u003c/code\u003e\u003c/td\u003e\n            \u003ctd\u003eProxy requests using HTTP Basic or Token Authentication.\n            Token is only used if user \u0026amp; password are not provided.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003eTIMEOUT\u003c/td\u003e\n            \u003ctd\u003e\u003ccode\u003eNone\u003c/code\u003e\u003c/td\u003e\n            \u003ctd\u003eTimeout value for proxy requests.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003eACCEPT_MAPS\u003c/td\u003e\n            \u003ctd\u003e\u003ccode\u003e{'text/html': 'application/json'}\u003c/code\u003e\u003c/td\u003e\n            \u003ctd\u003eModify Accept-headers before proxying them. You can use this to disallow certain types. By default \u003ccode\u003etext/html\u003c/code\u003e is translated to return JSON data.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003eDISALLOWED_PARAMS\u003c/td\u003e\n            \u003ctd\u003e\u003ccode\u003e('format',)\u003c/code\u003e\u003c/td\u003e\n            \u003ctd\u003eRemove defined query parameters from proxy request.\u003c/td\u003e\n        \u003c/tr\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n\n# SSL Verification #\nBy default, `django-rest-framework-proxy` will verify the SSL certificates when proxying requests, defaulting\nto security. In some cases, it may be desirable to not verify SSL certificates. This setting can be modified\nby overriding the `VERIFY_SSL` value in the `REST_PROXY` settings.\n\nAdditionally, one may set the `verify_proxy` settings on their proxy class:\n\n```python\n# views.py\nfrom rest_framework_proxy.views import ProxyView\n\nclass ItemListProxy(ProxyView):\n  \"\"\"\n  List of items\n  \"\"\"\n  source = 'items/'\n  verify_ssl = False\n\n```\n\nFinally, if there is complex business logic needed to determine if one should verify SSL, then\nyou can override the `get_verify_ssl()` method on your proxy view class:\n\n```python\n# views.py\nfrom rest_framework_proxy.views import ProxyView\n\nclass ItemListProxy(ProxyView):\n  \"\"\"\n  List of items\n  \"\"\"\n  source = 'items/'\n\n  def get_verify_ssl(self, request):\n    host = self.get_proxy_host(request)\n    if host.startswith('intranet.'):\n      return True\n    return False\n\n```\n\n# Permissions #\nYou can limit access by using Permission classes and custom Views.\nSee http://django-rest-framework.org/api-guide/permissions.html for more information\n```python\n# permissions.py\nfrom rest_framework.permissions import BasePermission, SAFE_METHODS\n\nclass AdminOrReadOnly(BasePermission):\n    \"\"\"\n    Read permission for everyone. Only admins can modify content.\n    \"\"\"\n    def has_permission(self, request, view, obj=None):\n        if (request.method in SAFE_METHODS or\n            request.user and request.user.is_staff):\n            return True\n        return False\n\n```\n```python\n# views.py\nfrom rest_framework_proxy.views import ProxyView\nfrom permissions import AdminOrReadOnly\n\nclass ItemListProxy(ProxyView):\n    permission_classes = (AdminOrReadOnly,)\n```\n\n\n#License#\n\nCopyright (c) 2014, Tomi Pajunen\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n2. 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.\n\nTHIS 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\nDISCLAIMED. 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feofs%2Fdjango-rest-framework-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feofs%2Fdjango-rest-framework-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feofs%2Fdjango-rest-framework-proxy/lists"}