I have implemented a REST API using Yii 2.0.8. The client can request JSON or XML response format either by using the Accept HTTP header or through a parameter in the URL. Likewise, either by using Accept-encoding:gzip or a URL parameter, the client can request the response to be gzipped. It all works beautifully with the exception that XML is properly gzipped while JSON is alwasy returned uncompressed.
There is a bug report on GitHub (#8331) just one year old without any follow up.
I could look into the code myself, but I cannot find where the compression is performed.