Skip to content
Expose a HAFAS client via an HTTP REST API.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples hafas-client@4 💥 Mar 22, 2019
lib hafas-client@4 💥 Mar 22, 2019
routes hafas-client@4 💥 Mar 22, 2019
test /stations -> /stops 💥 Mar 22, 2019
.editorconfig init from vbb-rest Dec 16, 2017
.gitignore init from vbb-rest Dec 16, 2017
.travis.yml Travis CI 💚 Mar 25, 2019
about-page.js about page: bugfixes 🐛 Mar 7, 2018
cors.js corser -> cors Sep 10, 2018
docs.js docsAsMarkdown option, 1.2.0 Feb 4, 2019
handle-errors.js morgan -> pino 💥 Mar 22, 2019
index.js temporarily support /stops/:id/departures as documented, 2.1.0 Aug 19, 2019
license.md 1.0.2 Aug 29, 2018
logging.js morgan -> pino 💥 Mar 22, 2019
package.json temporarily support /stops/:id/departures as documented, 2.1.0 Aug 19, 2019
readme.md

readme.md

hafas-rest-api

Expose a hafas-client@4 instance as an HTTP REST API.

npm version build status ISC-licensed chat on gitter support me on Patreon

Installing

npm install hafas-rest-api

Usage

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

const createApi = require('.')

const config = {
	hostname: 'example.org',
	port: 3000,
	name: 'my-hafas-rest-api',
	homepage: 'https://github.com/someone/my-hafas-rest-api',
	version: '1.0.0'
}

const hafas = createHafas(dbProfile, 'my-hafas-rest-api')
const api = createApi(hafas, config)

api.listen(config.port, (err) => {
	if (err) console.error(err)
})

config keys

key description mandatory? default value
hostname The public hostname of the API. ✔︎
port The port to listen on. ✔︎
cors Enable CORS? true
handleErrors Handle errors by sending 5** codes and JSON. true
logging Log requests using pino? false
healthCheck A function that returning Promises that resolve with true (for healthy) or false.
name The name of the API. Used for the X-Powered-By header and the about page. ✔︎
version Used for the X-Powered-By and X-API-Version headers.
homepage Used for the X-Powered-By header.
aboutPage Enable the about page on GET /? true
description Used for the about page.
docsLink Used for the about page.

Pro Tip: Use hafas-client-health-check for config.healthCheck.

Contributing

If you have a question or have difficulties using hafas-rest-api, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.

You can’t perform that action at this time.