Installations
npm install hafas-client-rpc
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=16
Node Version
20.5.1
NPM Version
9.8.0
Score
57.3
Supply Chain
77.8
Quality
73.5
Maintenance
100
Vulnerability
96.2
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Download Statistics
Total Downloads
5,243
Last Day
1
Last Week
4
Last Month
39
Last Year
463
GitHub Statistics
2 Stars
60 Commits
2 Watching
1 Branches
1 Contributors
Bundle Size
246.00 B
Minified
194.00 B
Minified + Gzipped
Package Meta Information
Latest Version
5.0.1
Package Id
hafas-client-rpc@5.0.1
Unpacked Size
26.55 kB
Size
8.34 kB
File Count
23
NPM Version
9.8.0
Node Version
20.5.1
Publised On
04 Sept 2023
Total Downloads
Cumulative downloads
Total Downloads
5,243
Last day
0%
1
Compared to previous day
Last week
33.3%
4
Compared to previous week
Last month
77.3%
39
Compared to previous month
Last year
-41.2%
463
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
10
Peer Dependencies
1
Dev Dependencies
4
hafas-client-rpc
Make JSON-RPC calls to hafas-client
via
- WebSockets – Supports reconnecting and load-balancing via
websocket-pool
. stdin
/stdout
- UNIX domain sockets
- NATS Streaming
Installation
1npm install hafas-client-rpc
Usage
Note: This version of hafas-client-rpc
only works with specific versions of hafas-client
. Check peerDependencies
in package.json
for details.
hafas-client-rpc
has multiple transports. Each of them has a client part (which sends commands to make HAFAS calls) and a server (which executes the HAFAS calls).
via WebSockets transport
With this transport, the server part is an actual WebSockets server, and the client connects to it.
1// server.js 2import http from 'http' 3import {createClient as createHafas} from 'hafas-client' 4import {profile as vbbProfile} from 'hafas-client/p/vbb/index.js' 5import exposeHafasClient from 'hafas-client-rpc/ws/server' 6 7const httpServer = http.createServer() 8httpServer.listen(3000) 9 10const hafas = createHafas(vbbProfile, 'my-awesome-program') 11const server = exposeHafasClient(httpServer, hafas)
1// client.js 2import createRoundRobin from '@derhuerst/round-robin-scheduler' 3import createClient from 'hafas-client-rpc/ws/client.js' 4 5const pool = createClient(createRoundRobin, [ 6 'ws://server-address:3000' 7 // pass more addresses here if you want 8], (_, hafas) => { 9 hafas.departures('900000009102') 10 .then(console.log) 11 .catch(console.error) 12}) 13pool.on('error', console.error)
Or using the websocat
command-line WebSocket client:
1echo 'departures 900000009102' | websocat --jsonrpc 'ws://server-address:3000'
via stdin
/stdout
transport
With this transport, the client spawns the server as a sub-process and sends commands via stdio.
1// server.js 2import {createClient as createHafas} from 'hafas-client' 3import {profile as vbbProfile} from 'hafas-client/p/vbb/index.js' 4import exposeViaStdio from 'hafas-client-rpc/stdio/server.js' 5 6const hafas = createHafas(vbbProfile, 'my-awesome-program') 7 8exposeViaStdio(hafas, (err) => { 9 console.log('hafas-client-rpc server ready') 10})
Creating a client in Node.js doesn't make sense, because you could just use hafas-client
directly. You would usually write the client in another language. For demonstration purposes, a Node client:
1// client.js 2import createClient from 'hafas-client-rpc/stdio/client.js' 3 4createClient('path/to/stdio/server.js', (_, hafas) => { 5 hafas.departures('900000009102') 6 .then(console.log) 7 .catch(console.error) 8})
with other languages
Spawn the stdio RPC server as a sub process of your script:
1node $(node -p 'require.resolve("hafas-client-rpc/stdio/simple-server.js")')
Send JSON-RPC 2.0 calls via stdin
:
1{"jsonrpc":"2.0","id":"1","method":"departures","params":["900000009102"]}
On success, you will receive the result via stdout
:
1{"jsonrpc":"2.0","id":"1","result":[{"tripId":"1|32623|3|86|8122018", …}]}
If an error occurs, you will receive it via stderr
:
1{"jsonrpc":"2.0","id":"1","error":{"message":"station ID must be a valid IBNR.","code":0,"data":{}}}
via UNIX domain sockets
With this transport, both client & server connect to a local TCP socket /tmp/hafas-client-rpc-{version}
.
1// server.js 2import {createClient as createHafas} from 'hafas-client' 3import {profile as vbbProfile} from 'hafas-client/p/vbb/index.js' 4import exposeViaSocket from 'hafas-client-rpc/socket/server.js' 5 6const hafas = createHafas(vbbProfile, 'my-awesome-program') 7 8exposeViaSocket(hafas)
1// client.js 2import createClient from 'hafas-client-rpc/socket/client.js' 3 4createClient((_, hafas) => { 5 hafas.departures('900000009102') 6 .then(console.log) 7 .catch(console.error) 8})
via NATS Streaming transport
This transport relies on NATS streaming channels. This allows you to have a pool of servers where an individual server can go offline at any time, as the channel will persist all RPC requests until they're taken care of. The transport uses two durable channels (one for RPC requests, the other for responses).
1// server.js 2import {createClient as createHafas} from 'hafas-client' 3import {profile as vbbProfile} from 'hafas-client/p/vbb/index.js' 4import exposeViaNatsStreaming from 'hafas-client-rpc/nats-streaming/server.js' 5 6const hafas = createHafas(vbbProfile, 'hafas-client-rpc WebSockets example') 7exposeViaNatsStreaming(hafas, (err) => { 8 if (err) console.error(err) 9})
1// client.js 2import createClient from 'hafas-client-rpc/nats-streaming/client.js' 3 4const pool = createClient((_, hafas) => { 5 hafas.departures('900000009102') 6 .then(console.log) 7 .catch(console.error) 8})
Caveats
hafas-client
exposes the used profile ashafasClient.profile
. Because these profiles consist of JavaScript functions, which can't be serialized properly, thehafas-client-rpc
facade does not expose.profile
.
Related
hafas-client
– JavaScript client for HAFAS public transport APIs.
Contributing
If you have a question or have difficulties using hafas-client-rpc
, 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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license.md:0
- Info: FSF or OSI recognized license: ISC License: license.md:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/derhuerst/hafas-client-rpc/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/derhuerst/hafas-client-rpc/test.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/test.yml:26
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Score
3.8
/10
Last Scanned on 2025-01-06
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreGathering detailed insights and metrics for hafas-client-rpc