createClient(options: ClientOptions): Client
Creates a MikroTik API client with automatic request multiplexing
Sets up encode/decode streams and manages request/reply correlation via automatic tagging. Multiple commands can be sent concurrently without waiting for previous commands to complete.
Basic client usage
Basic client usage
import { createClient } from "@hertzg/routeros-api/client"; // Create connection (example uses Deno, but works with any streams) const conn = await Deno.connect({ hostname: "192.168.88.1", port: 8728 }); // Create client const client = createClient({ readable: conn.readable, writable: conn.writable }); // Send command and get replies const replies = await client.send({ command: "/interface/print" }); // Close connection await client.quit();
Concurrent commands
Concurrent commands
import { createClient } from "@hertzg/routeros-api/client"; const conn = await Deno.connect({ hostname: "192.168.88.1", port: 8728 }); const client = createClient({ readable: conn.readable, writable: conn.writable }); // Send multiple commands concurrently (no waiting) const [interfaces, addresses, routes] = await Promise.all([ client.send({ command: "/interface/print" }), client.send({ command: "/ip/address/print" }), client.send({ command: "/ip/route/print" }) ]); await client.quit();
options: ClientOptions
Connection options with readable/writable streams
Client with send() and quit() methods