Implement ASP.NET Web API GZip compression ActionFilter
For this example with around 8 lines of code I will use very popular library for Compression / Decompression called DotNetZip library .This library can easily be downloaded from NuGet.
Now we implement Deflate compression ActionFilter.
We also need a helper class to perform compression.
For GZipCompressionAttribute implementation is exactly the same. You only need to call GZipStream instead of DeflateStream in helper method implementation.
If we want to mark some method in controller to be Deflated just put this ActionFilter attribute above method like this :
If you find some better way to perform this please let me know.