npm promotes metadefinitions
Have opinions about JavaScript? We want to hear them. Take the 2018 JavaScript Ecosystem Survey »

hafas-rest-api

1.1.2 • Public • Published

hafas-rest-api

Expose a hafas-client 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 morgan? 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.

install

npm i hafas-rest-api

Downloadsweekly downloads

297

version

1.1.2

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability