Runnable Node.js example
This client sends one search, prints progressive results, distinguishes text errors from binary results and waits for completion. It supports JSON and Protobuf without guessing frame types.
Set up a small example project
Section titled “Set up a small example project”Install ws and protobufjs in an empty directory. Save plan.mjs under examples/, then save all four schema files under proto/ next to that directory.
my-planner-example/ examples/plan.mjs proto/PlanRequest.proto proto/PlanResult.proto proto/Modes.proto proto/DirectionType.protonpm init -ynpm install ws protobufjsConnect with your Infoplaza API key
Section titled “Connect with your Infoplaza API key”Set your key in the terminal where you run the client:
export INFOPLAZA_API_KEY='YOUR_API_KEY'Replace YOUR_API_KEY with your Infoplaza API key. The client adds it as the api_key query parameter on wss://api.infoplaza.com/v1/transit/implanner.
Run Protobuf — recommended
Section titled “Run Protobuf — recommended”node examples/plan.mjsProtobuf is the default for both the client and the public endpoint. You can also select it explicitly with PLANNER_FORMAT=proto. On the connection URL, the equivalent optional parameter is mode=proto.
The script uses Utrecht Centraal / Science Park and the current time. Fare information and average walking and cycling speeds are included.
This Node.js example loads the schemas at startup. For a browser application, follow Generate TypeScript types to generate the client during development.
Try JSON
Section titled “Try JSON”PLANNER_FORMAT=json node examples/plan.mjsThe client connects to the same public endpoint with your API key and mode=json.
What to expect
Section titled “What to expect”Each response can contain multiple trips. The script prints times, duration, transfer count, optional fares and replay hashes. It prints routing errors separately and returns a failing process status for connection, decoding or terminal failures. The example times out after 60 seconds.
Download the complete client · Understand the lifecycle · Use a recipe