smurfy / mwo-api-sample

Api sample for mwo.smurfy-net.de
14 stars 5 forks source link

zip filter for api responses #10

Closed fat4eyes-mwo closed 7 years ago

fat4eyes-mwo commented 7 years ago

Hi smurfy,

I've been working on a little project and over the past several days have been pulling various API data from your site. I've noticed that one in particular

GET http:/mwo.smurfy-net.de/api/data/mechs.FORMAT

is pretty large (around 880kb). Since I don't want to cost you too much bandwidth and to reduce latency, it might be best if you apply a gzip filter to your api response code. If your code is in PHP here's how you can do it:

ob_start("ob_gzhandler");

before outputting any data and then

ob_end_flush();

after all the data has been echoed/printed. I've used it in my own php proxy script and it reduces the 880kb data to 58.8kb. It shouldn't affect any of the users of your API as almost all HTTP clients/libraries support HTTP compression (https://en.wikipedia.org/wiki/HTTP_compression).

I got the gzip filter tip from here (just FYI): https://stackoverflow.com/questions/19043284/how-to-get-send-gzip-content-as-php-response

Great job on all the data scraping and the API btw, they've been a great help on my little project.

smurfy commented 7 years ago

Thanks for the tip, i was quite sure i had gzip enabled in my webserver but i guess due to varnish i disabled it. I will do some tests but it should be easy to re-enable and varing for encoding in varnish.

smurfy commented 7 years ago

All responses should be gzip encoded now. (if the client requests it)