db-rest/docs/why.md
2020-05-01 20:13:45 +02:00

2.7 KiB

Why use this API?

Deutsche Bahn itself provides an API. Why use this one? (And what could DB do better?)

Realtime Data

This API returns realtime data whenever its upstream, the API for DB's mobile app, provides it.

No API Key

Especially on web sites/apps, it is a subpar solution to the send API keys to the client. Also, you have to obtain these keys manually and cannot automatically revoke them. This API doesn't require a key.

CORS

If you want to use transport information on a web site/app, CORS must be enabled. Otherwise, you would have to send all requests through your own proxy server. This API has CORS enabled.

Readable Markup

Compare the underlying HAFAS API:

{
	cid: 'C-0',
	date: '20171216',
	sDays: { /* … */ },
	dep: {
		locX: 0,
		dPlatfS: '6',
		dInR: true,
		dTimeS: '115400',
		dProgType: 'PROGNOSED',
		dTZOffset: 60,
		type: 'N'
	},
	arr: {
		locX: 2,
		aPlatfS: '4',
		aOutR: true,
		aTimeS: '162600',
		aProgType: 'PROGNOSED',
		aTZOffset: 60,
		type: 'N'
	},
	/* … */
}

to this one:

{
	origin: {
		type: 'station',
		id: '8089066',
		name: 'Berlin Friedrichstraße (S)',
		location: {
			type: 'location',
			latitude: 52.520331,
			longitude: 13.386934
		},
		products: {
			nationalExp: false,
			national: false,
			regionalExp: false,
			regional: true,
			suburban: true,
			bus: true,
			ferry: false,
			subway: true,
			tram: true,
			taxi: false
		},
	},
	destination: {
		type: 'station',
		id: '8004158',
		name: 'München-Pasing',
		location: {
			type: 'location',
			latitude: 48.150036,
			longitude: 11.461624
		},
		products: { /* … */ },
	},
	departure: '2017-12-16T11:54:00.000+01:00',
	arrival: '2017-12-16T16:26:00.000+01:00',
}

Caching-friendly

This API sends ETag & Cache-Control headers, allowing clients to refresh their state efficiently.

HTTP/2

HTTP/2 allows multiple requests at a time, efficiently pipelines sequential requests and compresses headers. See Cloudflare's HTTP/2 page.

Proper HTTP, Proper REST

This wrapper API follows REST-ful design principles, it uses GET, and proper paths & headers.

Monitoring

There's a status board that shows realtime uptime statistics.