
Virtualizing APIs with Go and Python - tjcunliffe
https://www.specto.io/?p=77
======
skywhopper
I don't think "virtualization" is quite the right word. "Middleware" is
better. "Protocol rewriting" might be more honest. Though in my day we just
called this a "hack".

It's certainly nothing new, whether you do it with a CGI script a fancy
rewrite module on your reverse proxy or a network "appliance" endpoint like a
BIG-IP. It's definitely something every good ops or devops person should be
able to pull off to fix those unfixable problems that crop up from vendor
intransigence or developer pushback.

------
nly
Isn't this just CGI, straight out of the 90s, but with a needless cycle
through JSON?

~~~
rakoo
There's a _huge_ difference: CGI is the ultimate backend in the HTTP stack,
while this allows you to run scripts as middleware (ie modifying the response
headers/body based on previous processing)

~~~
bmurphy1976
Not necessarily true. CGI could shell out to other CGI code if it wanted to.
Turtles all the way down.

~~~
rakoo
What if the backend is not CGI ? What if I want to use a script to gzip the
output of a backend that doesn't compress anything ? Of course you can just
call that backend through HTTP, but then you add another _huge_ dependency on
your little script that should just be as simple as "gzip -c -"

------
boomlinde
readlines() just to pick the first seems weird if you expect a single line.
I'd read the whole thing in one go with read(). Then I start wondering if it
wouldn't make more sense to keep the stream open and just iterate over new
messages line by line and avoid the overhead of loading an executable,
importing libraries etc. on every request

------
Lobster101
It is similar, but one advantage is that you can run your existing CGI scripts
(C/C++/perl/ ...) without a remote web server. That interests me as it would
allow re-use of some existing scripts and it would also allow me to wrap some
legacy interfaces.

------
_RPM
`data = sys.stdin.readlines()` in their Python script. Is it common to not
check return values of functions in Python land? I might be too disciplined
coming from a C background, but what if getting the data fails?

~~~
detaro
Then the function throws an exception and the program terminates, since there
isn't anything useful it can do about the situation. What would you suggest it
to do if it can't read from stdin?

------
jaytaylor
Direct link to Hoverfly source code:
[https://github.com/SpectoLabs/hoverfly](https://github.com/SpectoLabs/hoverfly)

------
carlisle_
Why is there image and whitespace that takes up >50% of the width of the page?
It makes it so obnoxious to read.

------
mring33621
So...AOP for web calls.

