https://github.com/public-transport/bvg-hafas
JavaScript client for the BVG HAFAS API.
https://github.com/public-transport/bvg-hafas
api berlin bvg hafas public-transport transit
Last synced: 7 months ago
JSON representation
JavaScript client for the BVG HAFAS API.
- Host: GitHub
- URL: https://github.com/public-transport/bvg-hafas
- Owner: public-transport
- License: isc
- Created: 2018-08-14T13:02:01.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-28T14:31:51.000Z (almost 3 years ago)
- Last Synced: 2024-04-14T07:11:20.115Z (over 1 year ago)
- Topics: api, berlin, bvg, hafas, public-transport, transit
- Language: JavaScript
- Homepage: https://github.com/public-transport/bvg-hafas#bvg-hafas
- Size: 40 KB
- Stars: 13
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# bvg-hafas
**A client for the [HAFAS](https://de.wikipedia.org/wiki/HAFAS) endpoint of [*Berliner Verkehrsbetriebe* (BVG)](https://en.wikipedia.org/wiki/Berliner_Verkehrsbetriebe), the largest public transport provider in Berlin.** It acts as a consistent and straightforward interface on top of their verbose API.
This project is actually a thin wrapper around [`hafas-client@6`](https://github.com/public-transport/hafas-client/tree/6#hafas-client). [Its docs](https://github.com/public-transport/hafas-client/tree/6/docs) document the API in general.
*Note*: The BVG HAFAS endpoint covers Brandenburg as well.
[](https://www.npmjs.com/package/bvg-hafas)

[](https://github.com/sponsors/derhuerst)
[](https://twitter.com/derhuerst)
## Installing
```shell
npm install bvg-hafas
```
## API
Check [the docs for `hafas-client@6`](https://github.com/public-transport/hafas-client/tree/6/docs) as well as [its BVG-specific customisations](https://github.com/public-transport/hafas-client/tree/6/p/bvg).
## Usage
```javascript
import {createBvgHafas} from 'bvg-hafas'
const client = createBvgHafas('my-awesome-program')
```
As an example, we will search for a route from *Berlin Jungfernheide* to *Tempelhof*. To get the station IDs, use [`locations(query, [opt])`](https://github.com/public-transport/hafas-client/blob/6/docs/locations.md).
```javascript
const journeys = await client.journeys('900020201', '900068201', {
results: 1,
})
console.log(journeys[0])
```
The output will be an array of [`journey` objects in the *Friendly Public Transport Format* `1.2.1` format](https://github.com/public-transport/friendly-public-transport-format/tree/1.2.1/spec#journey):
```javascript
{
type: 'journey',
legs: [ {
id: '1|62072|0|86|14082018',
origin: {
type: 'stop',
id: '900020201',
name: 'S+U Jungfernheide',
location: {
type: 'location',
latitude: 52.530273,
longitude: 13.299064
},
products: {
suburban: true,
subway: true,
tram: false,
bus: true,
ferry: false,
express: false,
regional: true
}
},
departure: '2018-08-14T15:05:00.000+02:00',
departurePlatform: '6',
departureDelay: 0,
destination: {
type: 'stop',
id: '900068201',
name: 'S+U Tempelhof',
location: {
type: 'location',
latitude: 52.470692,
longitude: 13.385756
},
products: { /* … */ }
},
arrival: '2018-08-14T15:27:00.000+02:00',
arrivalPlatform: '2',
arrivalDelay: 0,
direction: 'Ringbahn S 42',
line: {
type: 'line',
id: 's42',
name: 'S42',
public: true,
mode: 'train',
product: 'suburban',
operator: { /* … */ },
// …
},
cycle: { min: 300, max: 300 }
} ],
refreshToken: '…'
}
```
## Related
Check [`hafas-client`'s related projects](https://github.com/public-transport/hafas-client/blob/6/readme.md#related-projects).
## Contributing
If you **have a question**, **found a bug** or want to **propose a feature**, have a look at [the issues page](https://github.com/public-transport/bvg-hafas/issues).