About this task
Payload compression helps you to optimize the storage by reducing the
size of the actual payload. It improves the performance while rendering the
analytics information in the dashboard.
The request and response payload of the API Gateway API and native API
is compressed in the encoded form.
To generate the data and uncompress the
payload.
Procedure
-
Ensure you have an API enforced with a
Log invocation policy with the property
Compress payload data selected.
See the following example where an API is enforced with a Log
invocation policy with Compress payload data selected.
-
Invoke the same API using an external REST client such as Postman
or SoapUI to see the API transaction.
TransactionalEvent is generated every time an API invocation
happens.
-
Click
Analytics of the same API in
API Gateway
UI.
This displays the different types of events generated in the
dashboard. For details about analytics, see
Analytics Dashboards.
-
Select
Runtime events and click
to expand your
transaction.
-
Click
JSON or
Table and copy the encoded string (value) of
the request or response payload that you want to uncompress.
-
Pass the copied string as an
input to the following Java program.
public static String uncompressString(String zippedBase64Str) throws IOException {
String unCompressedPayload = null;
byte[] bytes = Base64.getDecoder().decode(zippedBase64Str);
GZIPInputStream zi = null;
try{
zi = new GZIPInputStream(new ByteArrayInputStream(bytes));
unCompressedPayload = IOUtils.toString(zi);
}finally{
IOUtils.closeQuietly(zi);
}
return unCompressedPayload;
}
See the following example, where an encoded string from the
request payload is passed as an
input to the Java program.
The Java
output contains the uncompressed payload.
Note: This code snippet is applicable only for the payload compressed
by the log invocation policy.
Results
You can also query the data using the REST endpoints from the
swagger file APIGatewaySearch.json and uncompress the payload with the same
code snippet.
For details about the REST endpoints, see
API Gateway Search.