{"id":21250909,"url":"https://github.com/natlee/django-simple-api-proxy","last_synced_at":"2025-07-11T01:31:39.759Z","repository":{"id":58663335,"uuid":"533012334","full_name":"NatLee/Django-Simple-API-Proxy","owner":"NatLee","description":"This is a tool for proxying any APIs on Django server.","archived":false,"fork":false,"pushed_at":"2022-12-14T15:49:31.000Z","size":20,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-01T18:15:51.309Z","etag":null,"topics":["api","django","proxy","proxy-pass","proxy-server"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/django-simple-api-proxy/","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/NatLee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-05T18:16:32.000Z","updated_at":"2025-03-19T14:48:19.000Z","dependencies_parsed_at":"2023-01-29T00:01:19.190Z","dependency_job_id":null,"html_url":"https://github.com/NatLee/Django-Simple-API-Proxy","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/NatLee/Django-Simple-API-Proxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NatLee%2FDjango-Simple-API-Proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NatLee%2FDjango-Simple-API-Proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NatLee%2FDjango-Simple-API-Proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NatLee%2FDjango-Simple-API-Proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NatLee","download_url":"https://codeload.github.com/NatLee/Django-Simple-API-Proxy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NatLee%2FDjango-Simple-API-Proxy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264705087,"owners_count":23652153,"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","django","proxy","proxy-pass","proxy-server"],"created_at":"2024-11-21T03:39:33.866Z","updated_at":"2025-07-11T01:31:39.465Z","avatar_url":"https://github.com/NatLee.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django Simple API Proxy\n\n[![Test](https://github.com/NatLee/Django-Simple-API-Proxy/actions/workflows/test.yml/badge.svg)](https://github.com/NatLee/Django-Simple-API-Proxy/actions/workflows/test.yml)[![Release](https://github.com/NatLee/Django-Simple-API-Proxy/actions/workflows/release.yml/badge.svg)](https://github.com/NatLee/Django-Simple-API-Proxy/actions/workflows/release.yml)\n\nThis is a simple tool for proxying any APIs easily on your Django server.\n\nYou can use it as middleware to make a layer for user authorization or something.\n\n## Installation\n\n```bash\npip install django-simple-api-proxy\n```\n\nCheck it in [Pypi](https://pypi.org/project/django-simple-api-proxy/).\n\n## Quick Start\n\n1. Add `django_simple_api_proxy` to your `INSTALLED_APPS` in `settings.py` like this:\n\n```py\nINSTALLED_APPS = [\n...\n'django_simple_api_proxy',\n]\n```\n\n2. Add APP settings to your `settings.py` like this:\n\n```py\nTARGET_API_URL = 'https://httpbin.org'\nPROXY_ROUTE_PATH = 'my_test_route'\nPROXY_TARGET_PATH = 'get'\n```\n\n3. Include the `django_simple_api_proxy` URL settings in your project `urls.py` like this:\n\n```py\nfrom django.conf import settings\nfrom django.urls import include\nurlpatterns += [\n    path(settings.PROXY_ROUTE_PATH, include('django_simple_api_proxy.urls'))\n]\n```\n\n4. Test on your server.\n\n```bash\npython manage.py runserver\n```\n\nHere's an example you success proxy an API by visit the following URLs.\n\n- http://127.0.0.1:8000/my_test_route/\n- http://127.0.0.1:8000/my_test_route\n\nAnd the result will be as below.\n\n```log\n[06/Sep/2022 01:26:04] \"GET /my_test_route/ HTTP/1.1\" 200 314\n2022-09-06 01:26:06.338 | DEBUG    | django_simple_api_proxy.views:get:73 - ----- Proxy GET\n2022-09-06 01:26:06.339 | DEBUG    | django_simple_api_proxy.views:get_proxy_path:37 - URL: /get\n2022-09-06 01:26:06.340 | DEBUG    | django_simple_api_proxy.views:update_payload:49 - Username: #anonymous\n```\n\n```json\n{\n  \"args\": { \"username\": \"#anonymous\" },\n  \"headers\": {\n    \"Accept\": \"*/*\",\n    \"Accept-Encoding\": \"gzip, deflate, br\",\n    \"Host\": \"httpbin.org\",\n    \"User-Agent\": \"python-requests/2.27.1\",\n    \"X-Amzn-Trace-Id\": \"Root=1-6316360c-2308560261599de4071127ac\"\n  },\n  \"origin\": \"xxx.xxx.xxx.xxx\",\n  \"url\": \"https://httpbin.org/get?username=%23anonymous\"\n}\n```\n\nBut when you visit `http://127.0.0.1:8000/my_test_route/123`, you'll get error.\n\nCause this URL is not found on target API server.\n\nSo, this proxy server will return this for you.\n\n```json\n{ \"status\": \"error\" }\n```\n\n## Usage\n\nAfter the quick start, you may want to change some methods with your API server like making an authorization.\n\nYou can do it with inheriting the `APIProxy` class.\n\nHere is an example:\n\n```py\n\nimport requests\n\nfrom rest_framework.authentication import SessionAuthentication\nfrom rest_framework_simplejwt.authentication import JWTAuthentication\nfrom rest_framework.permissions import IsAuthenticated\n\nfrom django_simple_api_proxy.views import APIProxy\n\nclass MyAPIProxy(APIProxy):\n    # give custom authentication\n    authentication_classes = [SessionAuthentication, JWTAuthentication]\n\n    # give custom permission\n    permission_classes = [IsAuthenticated]\n\n    def get(self, request, *args, **kwargs):\n        \"\"\"Get.\"\"\"\n        # your new `GET` logic here\n\n        logger.debug(\"----- Proxy GET Heyyaya\")\n        response = {\"status\": \"default error!!\"}\n        try:\n            params = dict(request.GET)\n            path = self.get_proxy_path(request)\n            params = self.update_payload(request, params)\n            middle_resp_ = self.send_request(\"GET\", path, params=params)\n            response = middle_resp_.json()\n        except Exception as e:\n            print('yooooo error occurs!!')\n            print(e)\n        return self.response(response)\n\n```\n\n## More\n\nThere is an example project you can check in [./example](https://github.com/NatLee/Django-Simple-API-Proxy/tree/main/example/api_proxy_example).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatlee%2Fdjango-simple-api-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnatlee%2Fdjango-simple-api-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnatlee%2Fdjango-simple-api-proxy/lists"}