2018-03-14 20:46:10 +01:00
|
|
|
|
# API documentation
|
|
|
|
|
|
|
|
|
|
- [`journeys(from, to, [opt])`](journeys.md) – get journeys between locations
|
2018-07-24 18:16:14 +02:00
|
|
|
|
- [`refreshJourney(refreshToken, [opt])`](refresh-journey.md) – fetch up-to-date/more details of a `journey`
|
2018-10-08 21:10:24 +02:00
|
|
|
|
- [`journeysFromTrip(tripId, previousStopover, to, [opt])`](journeys-from-trip.md) – get journeys from a trip to a location
|
2018-06-29 14:42:40 +02:00
|
|
|
|
- [`trip(id, lineName, [opt])`](trip.md) – get details for a trip
|
2019-12-17 14:12:35 +01:00
|
|
|
|
- [`tripsByName(lineNameOrFahrtNr, [opt])`](trips-by-name.md) – get all trips matching a name
|
2018-03-14 20:46:10 +01:00
|
|
|
|
- [`departures(station, [opt])`](departures.md) – query the next departures at a station
|
2018-06-26 17:11:25 +02:00
|
|
|
|
- [`arrivals(station, [opt])`](arrivals.md) – query the next arrivals at a station
|
2018-03-14 20:46:10 +01:00
|
|
|
|
- [`locations(query, [opt])`](locations.md) – find stations, POIs and addresses
|
2018-11-21 19:54:59 +01:00
|
|
|
|
- [`stop(id, [opt])`](stop.md) – get details about a stop/station
|
2018-03-14 20:46:10 +01:00
|
|
|
|
- [`nearby(location, [opt])`](nearby.md) – show stations & POIs around
|
|
|
|
|
- [`radar(north, west, south, east, [opt])`](radar.md) – find all vehicles currently in a certain area
|
2018-08-27 12:06:14 +02:00
|
|
|
|
- [`reachableFrom(address, [opt])`](reachable-from.md) – get all stations reachable from an address within `n` minutes
|
2020-03-09 20:54:43 +01:00
|
|
|
|
- [`remarks([opt])`](remarks.md) – get all remarks
|
2020-03-09 21:44:35 +01:00
|
|
|
|
- [`lines(query, [opt])`](lines.md) – get all lines matching a name
|
2020-03-09 19:47:29 +01:00
|
|
|
|
- [`serverInfo([opt])`](server-info.md) – fetch meta information from HAFAS
|
2018-03-14 22:52:36 +01:00
|
|
|
|
|
2018-12-10 20:27:51 +01:00
|
|
|
|
## Migrating from an old `hafas-client` version
|
|
|
|
|
|
2019-12-10 20:43:45 +01:00
|
|
|
|
- [`4` → `5` migration guide](migrating-to-5.md)
|
2018-12-10 20:27:51 +01:00
|
|
|
|
|
2019-02-08 13:14:19 +01:00
|
|
|
|
## Throttling requests
|
|
|
|
|
|
|
|
|
|
There's opt-in support for throttling requests to the endpoint.
|
|
|
|
|
|
|
|
|
|
```js
|
2019-02-08 14:59:21 +01:00
|
|
|
|
const createClient = require('hafas-client')
|
2019-10-31 18:48:11 +01:00
|
|
|
|
const withThrottling = require('hafas-client/throttle')
|
2019-02-08 13:14:19 +01:00
|
|
|
|
const dbProfile = require('hafas-client/p/db')
|
|
|
|
|
|
|
|
|
|
// create a throttled HAFAS client with Deutsche Bahn profile
|
2019-10-31 18:48:11 +01:00
|
|
|
|
const client = createClient(withThrottling(dbProfile), 'my-awesome-program')
|
2019-02-08 13:14:19 +01:00
|
|
|
|
|
|
|
|
|
// Berlin Jungfernheide to München Hbf
|
|
|
|
|
client.journeys('8011167', '8000261', {results: 1})
|
|
|
|
|
.then(console.log)
|
|
|
|
|
.catch(console.error)
|
|
|
|
|
```
|
|
|
|
|
|
2019-02-08 14:59:21 +01:00
|
|
|
|
You can pass custom values for the nr of requests (`limit`) per interval into `withThrottling`:
|
2019-02-08 13:14:19 +01:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// 2 requests per second
|
2019-10-31 18:48:11 +01:00
|
|
|
|
const throttledDbProfile = withThrottling(dbProfile, 2, 1000)
|
|
|
|
|
const client = createClient(throttledDbProfile, 'my-awesome-program')
|
2019-02-08 13:14:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Retrying failed requests
|
|
|
|
|
|
|
|
|
|
There's opt-in support for retrying failed requests to the endpoint.
|
|
|
|
|
|
|
|
|
|
```js
|
2019-02-08 15:07:35 +01:00
|
|
|
|
const createClient = require('hafas-client')
|
2019-10-31 18:48:11 +01:00
|
|
|
|
const withRetrying = require('hafas-client/retry')
|
2019-02-08 13:14:19 +01:00
|
|
|
|
const dbProfile = require('hafas-client/p/db')
|
|
|
|
|
|
|
|
|
|
// create a client with Deutsche Bahn profile that will retry on HAFAS errors
|
2019-10-31 18:48:11 +01:00
|
|
|
|
const client = createClient(withRetrying(dbProfile), 'my-awesome-program')
|
2019-02-08 13:14:19 +01:00
|
|
|
|
|
|
|
|
|
// Berlin Jungfernheide to München Hbf
|
|
|
|
|
client.journeys('8011167', '8000261', {results: 1})
|
|
|
|
|
.then(console.log)
|
|
|
|
|
.catch(console.error)
|
|
|
|
|
```
|
|
|
|
|
|
2019-02-08 15:07:35 +01:00
|
|
|
|
You can pass custom options into `withRetrying`. They will be passed into [`retry`](https://github.com/tim-kos/node-retry#tutorial).
|
2019-02-08 13:14:19 +01:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// retry 2 times, after 10 seconds & 30 seconds
|
2019-10-31 18:48:11 +01:00
|
|
|
|
const retryingDbProfile = withRetrying(dbProfile, {
|
2019-02-08 13:14:19 +01:00
|
|
|
|
retries: 2,
|
|
|
|
|
minTimeout: 10 * 1000,
|
|
|
|
|
factor: 3
|
|
|
|
|
})
|
2019-10-31 18:48:11 +01:00
|
|
|
|
const client = createClient(retryingDbProfile, 'my-awesome-program')
|
2019-02-08 13:14:19 +01:00
|
|
|
|
```
|
|
|
|
|
|
2018-03-14 22:52:36 +01:00
|
|
|
|
## Writing a profile
|
|
|
|
|
|
|
|
|
|
Check [the guide](writing-a-profile.md).
|
2019-12-20 18:02:48 +01:00
|
|
|
|
|
|
|
|
|
## General documentation for `mgate.exe` APIs
|
|
|
|
|
|
|
|
|
|
[`hafas-mgate-api.md`](hafas-mgate-api.md)
|