This repository contains two implementations of a generic HTTP proxy API: one using FastAPI and the other using Flask. Both APIs forward incoming requests to a target API specified via query parameters.
fast_api.py: Implementation using FastAPI with async support.flask_api.py: Implementation using Flask (synchronous).
- Supports all common HTTP methods:
GET,POST,PUT,DELETE,PATCH. - Forwards headers and body to the target API.
- Filters query parameters to exclude
apiwhen forwarding. - Excludes certain headers that may break the response (
content-encoding,transfer-encoding,connection).
- Create a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows- Install dependencies:
pip install fastapi[all] flask requests httpx uvicornRun the FastAPI proxy:
uvicorn fast_api:app --reload --port 8000Run the Flask proxy:
python flask_api.pycurl "http://127.0.0.1:8000/users/1?api=https://jsonplaceholder.typicode.com"- This will forward the request to
https://jsonplaceholder.typicode.com/users/1.
or
curl "http://127.0.0.1:8000/users/?api=https://api.telegram.org"- Both implementations forward headers and body.
- Use
apiquery parameter to specify the target API base URL. - Any additional query parameters will also be forwarded.
curl -X POST "http://127.0.0.1:8000/posts?api=https://jsonplaceholder.typicode.com" \
-H "Content-Type: application/json" \
-d '{"title": "foo", "body": "bar", "userId": 1}'- This forwards the POST request to the target API with JSON body.