3 ms·
mitmproxy (https://mitmproxy.org/ https://mitmproxy.org/) has scripting support that will let you do most of this. For example, you can expose mitmproxy, liste
by jeroenhd 5y ago
mitmproxy (https://mitmproxy.org/ https://mitmproxy.org/) has scripting support that will let you do most of this.
For example, you can expose mitmproxy, listen to HTTP requests for a specific host (using this API: https://docs.mitmproxy.org/stable/api/mitmproxy/http.html https://docs.mitmproxy.org/stable/api/mitmproxy/http.html), intercept the request, do whatever API calls you need, and inject a response without ever forwarding the request to the original server.
Alternatively, you could modify the request and then change the request destination, like in this example here: https://docs.mitmproxy.org/stable/addons-examples/#http-redirect-requests https://docs.mitmproxy.org/stable/addons-examples/#http-redi.... Using the WSGI support, you could even use normal Python annotations to build your own API without doing too much pattern matching: https://docs.mitmproxy.org/stable/addons-examples/#wsgi-flask-app https://docs.mitmproxy.org/stable/addons-examples/#wsgi-flas...
- Cilvic 5y agoOk. This sounds great for easy developing. But when I'm hosting this I'm not a mitmproxy. I want to act like a normal server/endpoint for API A.
- jeroenhd 5y agoI don't know any libraries for this in any good backend languages, but I've worked with these packages in NodeJS to do something like that: - https://www.npmjs.com/package/http-proxy https://www.npmjs.com/package/http-proxy - https://www.npmjs.com/package/connect https://www.npmjs.com/package/connect - https://www.npmjs.com/package/harmon https://www.npmjs.com/package/harmon If you don't want to act like a proxy, you're going to approach this like a normal web applications that does HTTP requests using whatever HTTP client your framework of choice uses.