trv-api-subscriber
v0.0.4
Published
A node.js module that subscribes to API:s at Trafikverket (Swedish Transport Administration) with SSE or by pulling delta data
Downloads
88
Readme
trv-api-subscriber
The Swedish Transport Administration (Trafikverket, or just TRV) provides an open API for trainrunning data (and road realated data). If attribute sseurl="true"
is added to the query tag, the API response will include an url for subscribing to new events through server send events (SSE).
Support for API JVG (B2B endpoint)
This plugin supports TRV´s B2B-endpoints. You can define custom headers as arguments. The bearer-token from first request is forwarded in the request to the SSE-endpoint.
Example usage:
// reference to module
const {SseClient} = require('trv-api-subscriber');
// TRV Query
const tposQuery = `<REQUEST>
<LOGIN authenticationkey="${openApiKey}"/>
<QUERY objecttype="TrainPosition" namespace="järnväg.trafikinfo" schemaversion="1.1" sseurl="true">
<FILTER>
<GT name="TimeStamp" value="${currentDateTimeIso}"/>
</FILTER>
</QUERY>
</REQUEST>
`;
new SseClient(openApiUrl, tposQuery, (data) => {
console.log(data);
});