mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-10-25 06:06:32 +03:00
2.9 KiB
2.9 KiB
API documentation
journeys(from, to, [opt])– get journeys between locationsrefreshJourney(refreshToken, [opt])– fetch up-to-date/more details of ajourneytrip(id, lineName, [opt])– get details for a tripdepartures(station, [opt])– query the next departures at a stationarrivals(station, [opt])– query the next arrivals at a stationlocations(query, [opt])– find stations, POIs and addressesstop(id, [opt])– get details about a stop/stationnearby(location, [opt])– show stations & POIs aroundradar(north, west, south, east, [opt])– find all vehicles currently in a certain areareachableFrom(address, [opt])– get all stations reachable from an address withinnminutes
Migrating from an old hafas-client version
Throttling requests
There's opt-in support for throttling requests to the endpoint.
const withThrottling = require('hafas-client/throttle')
const createClient = require('hafas-client')
const dbProfile = require('hafas-client/p/db')
// create a throttled HAFAS client with Deutsche Bahn profile
const createThrottledClient = withThrottling(createClient)
const client = createThrottledClient(dbProfile, 'my-awesome-program')
// Berlin Jungfernheide to München Hbf
client.journeys('8011167', '8000261', {results: 1})
.then(console.log)
.catch(console.error)
You can pass custom values for the nr of requests (limit) per interval into withThrottling:
// 2 requests per second
const createThrottledClient = withThrottling(createClient, 2, 1000)
const client = createThrottledClient(dbProfile, 'my-awesome-program')
Retrying failed requests
There's opt-in support for retrying failed requests to the endpoint.
const withRetrying = require('hafas-client/retry')
const createClient = require('hafas-client')
const dbProfile = require('hafas-client/p/db')
// create a client with Deutsche Bahn profile that will retry on HAFAS errors
const createRetryingClient = withRetrying(createClient)
const client = createRetryingClient(dbProfile, 'my-awesome-program')
// Berlin Jungfernheide to München Hbf
client.journeys('8011167', '8000261', {results: 1})
.then(console.log)
.catch(console.error)
You can pass custom options into withRetrying. They will be passed into retry.
// retry 2 times, after 10 seconds & 30 seconds
const createRetryingClient = withRetrying(createClient, {
retries: 2,
minTimeout: 10 * 1000,
factor: 3
})
const client = createRetryingClient(dbProfile, 'my-awesome-program')
Writing a profile
Check the guide.