All Projects → public-transport → Hafas Client

public-transport / Hafas Client

Licence: isc
JavaScript client for HAFAS public transport APIs.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Hafas Client

Vbb Modules
List of JavaScript modules for Berlin & Brandenburg public transport.
Stars: ✭ 47 (-62.4%)
Mutual labels:  api, transit, transport
ideas
How to make public transport more comfortable, more accessible, more transparent?
Stars: ✭ 35 (-72%)
Mutual labels:  transit, transport
open-bus
🚌 Analysing Israel's public transport data
Stars: ✭ 65 (-48%)
Mutual labels:  transit, transport
Node Pg Migrate
Node.js database migration management for Postgresql
Stars: ✭ 838 (+570.4%)
Mutual labels:  api, db
matsim-sbb-extensions
matsim swiss rail
Stars: ✭ 23 (-81.6%)
Mutual labels:  transit, transport
citylines
Citylines.co is a collaborative platform for mapping the transit systems of the world!
Stars: ✭ 53 (-57.6%)
Mutual labels:  transit, transport
Orbit Db Http Api
A HTTP API Server for the OrbitDB distributed peer-to-peer database
Stars: ✭ 17 (-86.4%)
Mutual labels:  api, db
bvg-topological-map
BVG transport map as a nice SVG.
Stars: ✭ 15 (-88%)
Mutual labels:  transit, transport
Vbb Cli
A CLI for Berlin & Brandenburg public transport.
Stars: ✭ 70 (-44%)
Mutual labels:  transit, transport
Tidytransit
R package for working with the General Transit Feed Specification (GTFS)
Stars: ✭ 84 (-32.8%)
Mutual labels:  transit, transport
TrenitaliaAPI
Reverse engineering dell'API dell'app di Trenitalia
Stars: ✭ 32 (-74.4%)
Mutual labels:  transit, transport
Gsheets Db Api
A Python DB-API and SQLAlchemy dialect to Google Spreasheets
Stars: ✭ 122 (-2.4%)
Mutual labels:  api, db
european-transport-operators
NOT UP-TO-DATE ANYMORE, UNMAINTAINED. CHECK european-transport-feeds INSTEAD. List of european long-distance transport operators, available API endpoints, GTFS feeds and client modules.
Stars: ✭ 47 (-62.4%)
Mutual labels:  transit, transport
public-transit-tools
Tools for working with GTFS public transit data in ArcGIS
Stars: ✭ 126 (+0.8%)
Mutual labels:  transit, transport
vbb-hafas
A JavaScript client for Berlin & Brandenburg public transport HAFAS API.
Stars: ✭ 28 (-77.6%)
Mutual labels:  transit, transport
vbb-rest
An HTTP API for Berlin & Brandenburg public transport.
Stars: ✭ 104 (-16.8%)
Mutual labels:  transit, transport
db-hafas
JavaScript client for the Deutsche Bahn HAFAS API.
Stars: ✭ 54 (-56.8%)
Mutual labels:  transit, transport
db-stations
A list of DB stations.
Stars: ✭ 15 (-88%)
Mutual labels:  transit, transport
European Transport Modules
[DISCONTINUED in favour of public-transport-operators] Collection of european transport JavaScript modules.
Stars: ✭ 9 (-92.8%)
Mutual labels:  transit, transport
Rapidql
Query multiple APIs and DBs and join them in a single query
Stars: ✭ 91 (-27.2%)
Mutual labels:  api, db

hafas-client

A client for the "mobile APIs" of HAFAS public transport management systems.

npm version build status ISC-licensed support Jannis via GitHub Sponsors chat with Jannis on Twitter

Background

A company called HaCon sells a public transport management system called HAFAS to public transport authorities and providers, mostly in Europe. It provides routing and departure information to their customers.

Most customers get their own, separate HAFAS deployments; They all use the same terminology and API calls, but have slightly different versions, configurations and sets of enabled features. Using built-in endpoint-specific customisations, hafas-client abstracts most of these differences away, and supports additional features in some cases. Check the list of supported networks/endpoints for more info.

Note: Currently, hafas-client only supports "mobile API" endpoints, which are designed for and used by the respective official mobile app(s); These endpoints almost always have mgate.exe in the URL. This library does not support "open API" endpoints (often they have rest-proxy or openapi in the URL) yet, but #134 contains work in progress.

Strictly speaking, permission is necessary to use this library with a HAFAS "mobile" endpoint. It merely tries to remove the technical barrier of accessing the data, in order to kick-start an ecosystem or apps and services that will eventually rely on openly available data.

Supported networks/endpoints

hafas-client has built-in support for many public transportation networks.

There are also libraries that use hafas-client and pass their own profile in:

HAFAS endpoint library
Betriebsstellen & disturbances in the German rail network db-netz-hafas

Installing

npm install hafas-client

with react-native

hafas-client as well its dependencies use Node-builtin modules and Node globals. To be able to use it within react-native, follow the instructions at node-libs-react-native.

Usage

Pick the profile for the HAFAS endpoint covering the area you want to get data for. Pass the profile and a descriptive name for your program into the createClient function:

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

// create a client with the Deutsche Bahn profile
const client = createClient(dbProfile, 'my-awesome-program')

You can now use client to query the HAFAS endpoint configured in the db profile:

// Berlin Jungfernheide to München Hbf
const res = await client.journeys('8011167', '8000261', {results: 1})
console.log(res)

journeys() returns a Promise that will resolve with an object with an array journeys that contains one Friendly Public Transport Format (FPTF) 1.2.1 journey.

{
	journeys: [ {
		origin: {
			type: 'station',
			id: '8089100',
			name: 'Berlin Jungfernheide (S)',
			location: { /* … */ },
			products: { /* … */ }
		},
		departure: '2017-12-19T17:05:30+01:00',
		plannedDeparture: '2017-12-19T17:05:00+01:00',
		departureDelay: 30,
		departurePlatform: '5',
		plannedDeparturePlatform: '5',

		destination: {
			type: 'station',
			id: '8000261',
			name: 'München Hbf',
			location: { /* … */ },
			products: { /* … */ }
		},
		arrival: '2017-12-19T22:44:00+01:00',
		plannedArrival: '2017-12-19T22:45:00+01:00',
		arrivalDelay: -60,
		arrivalPlatform: '11A',
		plannedArrivalPlatform: '13',

		legs: [ {
			id: '1|100067|48|81|17122017',
			line: {
				type: 'line',
				id: '41172',
				name: 'S 41',
				public: true,
				mode: 'train',
				product: 'suburban',
				operator: {
					type: 'operator',
					id: 's-bahn-berlin-gmbh',
					name: 'S-Bahn Berlin GmbH'
				}
			},
			direction: 'Ringbahn ->',

			origin: {
				type: 'station',
				id: '8089100',
				name: 'Berlin Jungfernheide (S)',
				location: {
					type: 'location',
					latitude: 52.530291,
					longitude: 13.299451
				},
				products: { /* … */ }
			},
			departure: '2017-12-19T17:05:30+01:00',
			plannedDeparture: '2017-12-19T17:05:00+01:00',
			departureDelay: 30,
			departurePlatform: '5',
			plannedDeparturePlatform: '5',

			destination: {
				type: 'station',
				id: '8089118',
				name: 'Berlin Beusselstraße'
				// …
			},
			arrival: '2017-12-19T17:08:00+01:00',
			plannedArrival: '2017-12-19T17:08:00+01:00',
			arrivalDelay: null,
			arrivalPlatform: '2a-b',
			plannedArrivalPlatform: '1'
		},
		/* more legs… */
		{
			walking: true,
			public: true,

			origin: {
				type: 'station',
				id: '730749',
				name: 'Berlin Hauptbahnhof (S+U), Berlin'
				// …
			},
			plannedDeparture: '2017-12-19T17:25:00+01:00',
			prognosedDeparture: null,
			departureDelay: null,

			destination: {
				type: 'station',
				id: '8098160',
				name: 'Berlin Hbf (tief)'
				// …
			},
			arrival: '2017-12-19T17:33:00+01:00',
			plannedArrival: '2017-12-19T17:33:00+01:00',
			arrivalDelay: null
		}, {
			id: '1|70906|0|81|17122017',
			line: { /* … */ },
			direction: 'München Hbf',

			origin: {
				type: 'station',
				id: '8098160',
				name: 'Berlin Hbf (tief)'
				// …
			},
			departure: '2017-12-19T17:35:00+01:00',
			plannedDeparture: '2017-12-19T17:37:00+01:00',
			departureDelay: -120,
			departurePlatform: '1',
			plannedDeparturePlatform: '1',

			destination: {
				type: 'station',
				id: '8000261',
				name: 'München Hbf',
				// …
			},
			arrival: '2017-12-19T22:44:00+01:00',
			plannedArrival: '2017-12-19T22:45:00+01:00',
			arrivalDelay: -60,
			arrivalPlatform: '11A',
			plannedArrivalPlatform: '13'
		} ],
		price: {
			amount: null,
			hint: 'No pricing information available.'
		}
		// …
	} ]
	// …
}

Each profile has more detailed example code.

in the browser

While hafas-client itself should work in the browser via a bundler like Webpack, most HAFAS API endpoints don't enable CORS, so you won't be able query them directly.

API

API documentation

Related

More related libraries can be found via the npm package index.

Contributing

If you have a question, found a bug or want to propose a feature, please open an Issue.

This project needs help! Check the list of "help wanted" Issues.

If you're contributing code, please read the contribution guidelines.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].