This is a small blog post, in which we will go through the steps to add response compression in our Java-based Lagom service. If you are not familiar with the concepts of Lagom, read through this blog to gain a brief idea of what Lagom is all about. Then, come back here and we will add quickly add compression to the service you’d have implemented.
Below are the two simple steps to add service response compression to your Lagom service.
Step 1: The Code
The first step is to write the code for our compression filter. We design a custom Filter that implements the HttpFilters interface provided by play framework as illustrated below. Let’s say we want to add GZip compression to our response before sending it to the consumer. The below snippet can be used as is in any Lagom service.
Step 2: The configuration
In your application.conf, add the below parameters:
And you’re done!
This is the simplest way to add compression to your service response with minimal configuration. To study in further detail, feel free to explore the documentation of Play GZipEncoding. If you have any questions, queries or suggestions for me, please drop a comment below and I’ll be happy to answer. And if you found this useful, do like & share this blog, we are all here to learn! Cheers. 🙂