Entur SDK
Edit page
Entur SDKGetting StartedInstallSetup
Geocoder
Travel
Departures
Places
Bikes
Scooters
Utils
Advanced

Install

npm install @entur/sdk --save

Setup

Import the service creator:

import createEnturService from '@entur/sdk'

Or if you are using CommonJS:

const createEnturService = require('@entur/sdk').default

Then create an instance of the service:

const service = createEnturService({ clientName: 'awesomecompany-awesomeapp' })

Configuration

NameRequired?TypeDefaultDescription
clientNameYesstringundefinedThe name of your application
hostsNo{object of hosts}{}Override default endpoints
fetchNofunctionnative fetch if browser, node-fetch if Node.JS

clientName (required)

We require that you pass a clientName that identifies your application. It should contain the name of your company or organization, followed by a hyphen and your application's name. See https://developer.entur.org/pages-intro-authentication for more information.

hosts

The Entur SDK uses multiple endpoints for its services. Each endpoint can be overridden with hosts config (in case you use a proxy or a local instance of the endpoint). Available hosts are:

{
journeyPlanner: '',
geocoder: '',
scooters: '',
}

fetch

If you need to configure the fetch implementation that is used, use this. You could use this for:

  • Specifying default headers
  • Specifying custom agents
  • Do some common logging on all SDK requests
const service = createEnturService({
clientName: 'awesomecompany-awesomeapp',
fetch: (url, init) => {
const startTime = new Date()
console.log(`Request at: ${startTime.toString()}`)
return fetch(url, {
agent: new HttpsAgent({ keepAlive: true }),
...init,
headers: {
'My-Default-Header': 'cheese',
...init.headers
}
}).then(res => {
console.log(`Response after ${new Date() - startTime} ms`)
return res
})
}
})