Registry / devops / hafas-rest-api

hafas-rest-api

JSON →
library5.1.3jsnpmunverified

Expose a HAFAS client (e.g., for Deutsche Bahn, SBB, etc.) via an HTTP REST API. v5.1.3. Works as a middleware for Express or Node http modules, enabling integration of public transport timetable data into web apps. Key differentiator: wraps the hafas-client library into a standardized REST interface, supporting multiple HAFAS endpoints with a unified configuration approach.

npm install hafas-rest-api
INSTALL
IMPORT
SIG · HAFAS-REST-API
H
hafas-rest-api
devopsjavascriptv5.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import createApi from 'hafas-rest-api'
const createApi = require('hafas-rest-api')
ESM-only since v5; CJS require is not supported. Also note the default export is a factory function, not a class.
createApi
import createApi from 'hafas-rest-api'
import { createApi } from 'hafas-rest-api'
createApi is the default export, not a named export. Named import will fail.
createApi
import createApi from 'hafas-rest-api'; const app = createApi(hafasClient, { /* options */ })
import * as hafasApi from 'hafas-rest-api'; const app = hafasApi.createApi(hafasClient)
Namespace import then calling createApi as a property works, but direct default import is simpler.

Shows how to create a HAFAS REST API server using the default export from hafas-rest-api with an Express-compatible handler.

import createClient from 'hafas-client'; import createApi from 'hafas-rest-api'; import { createServer } from 'node:http'; const client = createClient('db'); // Replace 'db' with your HAFAS profile const api = createApi(client, { // Optional: specify port, rate limiting, etc. }); const server = createServer(api); server.listen(3000, () => { console.log('HAFAS REST API running on http://localhost:3000'); });
Debug
Known issues
breakingESM-only since v5; CommonJS require() will fail.
fix
Convert project to ESM (type: "module" in package.json) and use import syntax.
affects: >=5.0.0
breakingVersion 5 requires hafas-client v6 as a peer dependency.
fix
Update hafas-client to version 6 in your dependencies.
affects: >=5.0.0
gotchaThe API endpoints are mounted at / by default, which may conflict with other routes in an Express app.
fix
Use the path option to set a base path, e.g., { path: '/api' }.
affects: all
gotchaRate limiting is not enabled by default; you must configure it via options to avoid abuse.
fix
Set rateLimit option during API creation.
affects: all
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using require() to import hafas-rest-api which is ESM-only.
fix
Change to import statement: import createApi from 'hafas-rest-api';
TypeError: createApi is not a function
Wrong import: using named import { createApi } instead of default import.
fix
Use default import: import createApi from 'hafas-rest-api';
Error: Cannot find module 'hafas-client'
Missing peer dependency hafas-client.
fix
Install hafas-client: npm install hafas-client
Upgrade
Version history
5.1.3latest on npm
Audit
Dependencies
hafas-clientrequiredpeer dependency; the actual HAFAS client implementation to wrap
Agent activity
16 hits · last 30 days
node
12
Resources
hafas-rest-api — npm install hafas-rest-api · libregistry