Table of contents
- Java RestTemplate
- Rate limiting
- Authentication in weathercam requests
- MQTT disconnects
Q: Why do APIs often return the same response?
A: Most of the service calls are cached. Therefore, there is no gain calling the services too often, as the response will not change. Most of the caches are one minute long.
This might lead to some oddities with updated timestamps. For example:
These two might return a different dataUpdatedTime because the calls were cached at different time.
Q: How can I request data in a more efficient way?
A: Using compression is highly recommended. The data compress well and you can save bandwith and time. How to use compression is dependant of the tools and frameworks you are using.
curl -H 'Accept-Encoding: gzip'
wget --header='Accept-Encoding: gzip'
Q: How do I call the APIs with cURL?
curl -H 'Accept-Encoding: gzip' -H 'Connection: close' --compress https://tie.digitraffic.fi/api/v1/data/tms-data -o data.json
Q: How do I call the APIs with Wget?
wget --header='Accept-Encoding: gzip' --header='Connection: close' https://tie.digitraffic.fi/api/v1/data/tms-data -O data.json
Q: How do I call the APIs with Java RestTemplate?
final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create().build()); final RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory); final String output = restTemplate.getForObject("https://tie.digitraffic.fi/api/v1/data/tms-data?testi=testi", String.class);
Q: Why do some of my API requests fail with code 429?
A: Some APIs can be called with a certain amount in a certain time window. The API contents are not updated more often than the API can be called.
Q: Why do my weathercam API requests fail with code 400?
A: Check if you using the Authorization header in your requests. Using this header will cause weathercam requests to fail.
Q: Why does my mqtt-connection keep disconnecting?
A: You have not subscribed any topic or subscribed only topics that have infrequent messages. Subscribe also to relevan status-topic(tms/status, weather/status or vessels/status).