Instructions

Instructions for coding

Table of contents

Cache

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:

https://tie.digitraffic.fi/api/v1/data/tms-data?lastUpdated=true

https://tie.digitraffic.fi/api/v1/data/tms-data?lastUpdated=false

These two might return a different dataUpdatedTime because the calls were cached at different time.

Compression

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

curl -H 'Accept-Encoding: gzip'

Wget

wget --header='Accept-Encoding: gzip'

cURL

Q: How do I call the APIs with cURL?
A:

curl -H 'Accept-Encoding: gzip' -H 'Connection: close' --compress https://tie.digitraffic.fi/api/v1/data/tms-data -o data.json

Wget

Q: How do I call the APIs with Wget?
A:

wget --header='Accept-Encoding: gzip' --header='Connection: close' https://tie.digitraffic.fi/api/v1/data/tms-data -O data.json

Java RestTemplate

Q: How do I call the APIs with Java RestTemplate?
A:

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);

Rate limiting

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.

Authentication in weathercam requests

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.

MQTT disconnects

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).

bug_reportDid you find an error? Help us improve this page.