Socket
Socket
Sign inDemoInstall

hafas-rest-api

Package Overview
Dependencies
129
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

hafas-rest-api

Expose a HAFAS client via an HTTP REST API.


Version published
Maintainers
1
Weekly downloads
8
decreased by-61.9%

Weekly downloads

Readme

Source

hafas-rest-api

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

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

Installing

npm install hafas-rest-api

Usage

import {createClient as createHafas} from 'hafas-client'
import {profile as dbProfile} from 'hafas-client/p/db/index.js'
import {createHafasRestApi as createApi} from 'hafas-rest-api'

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

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

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

config keys

keydescriptionmandatory?default value
hostnameThe public hostname of the API.✔︎
nameThe name of the API. Used for the X-Powered-By header and the about page.✔︎
descriptionUsed for the about page.✔︎ (with aboutPage: true)
docsLinkUsed for the about page.✔︎ (with aboutPage: true)
corsEnable CORS?true
etagsExpress config for ETag headersweak
handleErrorsHandle errors by sending 5** codes and JSON.true
loggingLog requests using pino?false
healthCheckA function that returning Promises that resolve with true (for healthy) or false.
versionUsed for the X-Powered-By and X-API-Version headers.
homepageUsed for the X-Powered-By header.
aboutPageEnable the about page on GET /?true
openapiSpecGenerate and serve an OpenAPI spec of the API?false
addHafasOptsComputes additional hafas-client opts. (opt, hafasClientMethod, httpReq) => additionaOpts
modifyRoutesExtend or modify the default routes.routes => routes

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.

Keywords

FAQs

Last updated on 26 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc