db-vendo-client/docs
2019-02-28 16:24:09 +01:00
..
arrivals.md query arrivals , docs 📝 2018-06-26 18:13:41 +02:00
changelog.md changelog 📝, permalinks to 3 branch 📝, 3.10.1 2019-02-28 16:24:09 +01:00
departures.md arrivals/departures: opt.stopovers for previous/next stopovers, docs 📝 2018-12-28 22:14:35 +01:00
journeys.md parse scheduled days of a journey 2018-10-25 18:57:31 +02:00
locations.md adapt docs & examples to 0a0cddc 📝 2018-07-24 18:29:31 +02:00
migrating-to-3.md more related libs, tiny docs fixes 📝 2019-01-07 16:23:40 +08:00
nearby.md minor changes 2018-10-15 20:10:50 +02:00
profile-boilerplate.js rename profile.journeyLeg to profile.trip 💥 2018-07-07 21:19:28 +02:00
radar.md radar: fix polylines option 🐛 2018-12-13 19:30:55 +01:00
reachable-from.md readableFrom: make maxDuration optional 2018-11-01 19:39:04 +01:00
readme.md docs for retry & throttle 📝 2019-02-08 13:17:05 +01:00
refresh-journey.md link to FPTF 1.2.0 📝 2018-09-22 19:25:01 +02:00
station.md docs/station: fix formatting 2018-07-24 18:29:31 +02:00
trip.md trip: remove when option, it gets ignored anyways 2018-10-15 20:10:50 +02:00
writing-a-profile.md link to FPTF 1.2.0 📝 2018-09-22 19:25:01 +02:00

API documentation

Throttling requests

There's opt-in support for throttling requests to the endpoint.

const createThrottledClient = require('hafas-client/throttle')
const dbProfile = require('hafas-client/p/db')

// create a throttled HAFAS client with Deutsche Bahn profile
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 createThrottledClient:

// 2 requests per second
const client = createThrottledClient(dbProfile, 'my-awesome-program', 2, 1000)

Retrying failed requests

There's opt-in support for retrying failed requests to the endpoint.

const createClientWithRetry = require('hafas-client/retry')
const dbProfile = require('hafas-client/p/db')

// create a client with Deutsche Bahn profile that will retry on HAFAS errors
const client = createClientWithRetry(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 createClientWithRetry. They will be passed into retry.

// retry 2 times, after 10 seconds & 30 seconds
const client = createClientWithRetry(dbProfile, 'my-awesome-program', {
	retries: 2,
	minTimeout: 10 * 1000,
	factor: 3
})

Writing a profile

Check the guide.