1) HAFAS Client Initialization
createHafas(dbProfile, userAgent) configures a client for OEBB semantics such as station identifiers, line products, and request conventions.
Readable reference
This API wraps HAFAS OEBB data behind predictable REST endpoints. Use it for station search, departures, arrivals, journeys, trip details, and radar. The documentation below focuses on clarity and practical integration patterns.
The server flow is compact: create profile-aware HAFAS client, generate REST handlers, mount handlers under /api. This architecture keeps behavior consistent while exposing many transport functions.
createHafas(dbProfile, userAgent) configures a client for OEBB semantics such as station identifiers, line products, and request conventions.
createApi(hafas, config) maps HAFAS capabilities like journeys, departures, and radar to HTTP routes with normalized JSON output.
expApp.use('/api', api) groups all transport endpoints under one base path, simplifying reverse proxies and integration setup.
Routes / and /docs serve human-readable pages while /api remains machine-oriented JSON.
curl "http://localhost:3000/api/locations?query=Wien" curl "http://localhost:3000/api/stops/8103000/departures?duration=90&results=8" curl "http://localhost:3000/api/journeys?from=Wien%20Hbf&to=Salzburg%20Hbf&results=3"
Search stations, addresses, and points of interest from user text.
| Parameter | Type | Description |
|---|---|---|
| query | string | Search term such as Wien Hbf or Graz. |
| results | number | Optional maximum number of entries. |
curl "http://localhost:3000/api/locations?query=Innsbruck&results=5"
Find stops and places around a coordinate, useful for map pickers and station suggestions.
| Parameter | Type | Description |
|---|---|---|
| latitude | number | Center latitude. |
| longitude | number | Center longitude. |
| distance | number | Optional radius in meters. |
curl "http://localhost:3000/api/locations/nearby?latitude=48.2082&longitude=16.3738&distance=600"
Read upcoming departures for a stop, including line and direction details.
| Parameter | Type | Description |
|---|---|---|
| id | string | Stop ID, for example 8103000. |
| duration | number | Optional time window in minutes. |
| results | number | Optional number of departures. |
curl "http://localhost:3000/api/stops/8103000/departures?duration=120&results=10"
Plan connections between two locations with transfer and timing information.
| Parameter | Type | Description |
|---|---|---|
| from | string | Origin stop name or ID. |
| to | string | Destination stop name or ID. |
| departure | ISO datetime | Optional desired departure time. |
| results | number | Optional number of journey options. |
curl "http://localhost:3000/api/journeys?from=Wien%20Hbf&to=Salzburg%20Hbf&results=4"
Trip details provide stopovers for one service. Radar provides moving vehicles in a bounding box.
curl "http://localhost:3000/api/trips/TRIP_ID_HERE" curl "http://localhost:3000/api/radar?north=48.35&west=16.15&south=48.10&east=16.55&results=25"
Call one stop endpoint, then render when, line, direction, platform, and delay. Refresh on a short interval for active stations.
const res = await fetch('http://localhost:3000/api/stops/8103000/departures?results=6');
const data = await res.json();
for (const dep of data.departures) {
console.log(dep.when, dep.line?.name, dep.direction, dep.platform, dep.delay);
}Resolve user input with location search first, then call journeys with stable IDs where available.
const fromCandidates = await fetch('http://localhost:3000/api/locations?query=Linz').then(r => r.json());
const toCandidates = await fetch('http://localhost:3000/api/locations?query=Graz').then(r => r.json());
const from = fromCandidates[0]?.id || 'Linz Hbf';
const to = toCandidates[0]?.id || 'Graz Hbf';
const journeyUrl = 'http://localhost:3000/api/journeys?from=' + encodeURIComponent(from) + '&to=' + encodeURIComponent(to) + '&results=3';
const journeyData = await fetch(journeyUrl).then(r => r.json());
console.log(journeyData.journeys?.length || 0);Most responses provide timing fields, line metadata, and identifiers suitable for caching and follow-up calls.
{
"departures": [
{
"tripId": "...",
"when": "2026-05-11T09:42:00+02:00",
"plannedWhen": "2026-05-11T09:40:00+02:00",
"delay": 120,
"platform": "7",
"direction": "Salzburg Hbf",
"line": {
"name": "RJX 168",
"product": "nationalExpress"
}
}
]
}