Gzip Compression
Important notes:
- This TomTom Orbis API is in public preview.
- This API is powered by the TomTom Orbis Maps.
- See the TomTom Orbis Maps documentation for more information.
Enabled by default
Since 1st December 2024 new customers receive all Intermediate Traffic Feed responses compressed with Gzip.
The use of the Accept-Encoding: gzip
HTTP header is recommended, but not required.
Benefits of Gzip compression
TomTom observed that Gzip compression is beneficial for several reasons:
Benefit | Description |
---|---|
Faster feed downloads | Compressed feeds are much smaller and therefore faster to download. Our tests show that:
|
Faster processing time | The overall processing time of new snapshots will be greatly reduced, which results in fresher data.
|
Easy to implement | Enabling Gzip is usually straightforward because it’s supported out-of-the-box by many client libraries. |
I'm still not using Gzip compression, how can I start using it?
Customers that still don't use Gzip compression can decide at any time to request the Gzip-compressed feed and receive the same content, in the same format, while leveraging the benefits of a more efficient encoding.
Follow these steps to enable Gzip compression:
- Configure your HTTP client: Depending on your HTTP client library, enabling compression could be just an option to set or you might need to manually add the
Accept-Encoding: gzip
header to HTTP requests. - Test: Request a feed and verify that the content is correctly decompressed. Depending on your HTTP client library, this might happen automatically or you might need to specify a decompression handler.
Check the following instructions for common client libraries.
The following instructions are intended as general guidelines. Actual changes may vary slightly depending on the library version and your specific implementation.
cURL
Steps:
- Add the
--compressed
option (official documentation). - Decompression will happen automatically.
Wget
Steps:
- Add the
--compression=gzip
option (official documentation). - Decompression will happen automatically.
Java: HttpsURLConnection
Steps:
-
Add the
Accept-Encoding: gzip
header to thejavax.net.ssl.HttpsURLConnection
instance:httpsURLConnection.setRequestProperty("Accept-Encoding" , "gzip"); -
Wrap the response input stream with
java.util.zip.GZIPInputStream
:InputStream inputStream = new GZIPInputStream(httpsURLConnection.getInputStream());
Java: Jakarta Commons HttpClient
Jakarta Commons HttpClient (now renamed to “Apache HttpComponents”) transparently supports compression by default since version 4.1, but we suggest upgrading to more recent versions. See the official documentation.
If you cannot upgrade, you might need to take the following steps:
-
Add the
Accept-Encoding: gzip
header to theorg.apache.commons.httpclient.methods.GetMethod
instance:getMethod.addRequestHeader("Accept-Encoding" , "gzip"); -
Wrap the response input stream with
java.util.zip.GZIPInputStream
:InputStream inputStream = new GZIPInputStream(getMethod.getResponseBodyAsStream());
Python: ‘requests’ library
Steps:
-
Add the
Accept-Encoding: gzip
header torequests
:1import requests2# ...3request_headers = {'Accept-Encoding': 'gzip'}4response = requests.get(url, headers=request_headers) -
Decompression will happen automatically (official documentation).
Python: urllib.request module
Steps:
-
Add the
Accept-Encoding: gzip
header to theurllib.request.Request
(official documentation):1import urllib.request2# ...3request_headers = {'Accept-Encoding': 'gzip'}4request = urllib.request.Request(url, headers=request_headers) -
Add
gzip.decompress
to the existing code that reads the response content:1import gzip2# ...3response_data = gzip.decompress(response.read())