On this page & docs navigation
One interface · implementations in every language

Integrate in a language you already know

The clientoffers no JS wrapper, providing only REST and native WebSocket channels. Every language below calls the API directly with its own HTTP / WebSocket capabilities — switch tabs to see each implementation. The examples use the default address http://127.0.0.1:19861; if you changed the port in settings, adjust to the actual value.

REST general commands

POST /api/command: the body is "command name + that command's JSON parameters". The example below is template waybill printing; high-frequency operations can also use the convenience endpoints (/api/print, /api/escpos , etc.).

curl -X POST "http://127.0.0.1:19861/api/command" \
  -H "Content-Type: application/json" \
  -d '{
    "cmd": "TemplatePrint",
    "html": t("<div>收件人:{{name}} {{addr}}</div>"),
    "data": { "name": t("张伟"), "addr": t("广州市天河区体育西路 100 号") },
    "printer": "HP LaserJet Pro M404",
    "paperKind": "100x150"
  }'
const base = "http://127.0.0.1:19861";
const r = await fetch(base + "/api/command", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    cmd: "TemplatePrint",
    html: t("<div>收件人:{{name}} {{addr}}</div>"),
    data: { name: t("张伟"), addr: t("广州市天河区体育西路 100 号") },
    printer: "HP LaserJet Pro M404",
    paperKind: "100x150"
  })
});
const result = await r.json();
import json, urllib.request
payload = {
    "cmd": "TemplatePrint",
    "html": t("<div>收件人:{{name}} {{addr}}</div>"),
    "data": {"name": t("张伟"), "addr": t("广州市天河区体育西路 100 号")},
    "printer": "HP LaserJet Pro M404",
    "paperKind": "100x150"
}
req = urllib.request.Request(
    "http://127.0.0.1:19861/api/command",
    data=json.dumps(payload).encode(),
    headers={"Content-Type": "application/json"}
)
with urllib.request.urlopen(req) as r:
    result = json.load(r)
var base = "http://127.0.0.1:19861";
using var http = new HttpClient();
var payload = new {
    cmd = "TemplatePrint",
    html = t("<div>收件人:{{name}} {{addr}}</div>"),
    data = new { name = t("张伟"), addr = t("广州市天河区体育西路 100 号") },
    printer = "HP LaserJet Pro M404",
    paperKind = "100x150"
};
var resp = await http.PostAsJsonAsync(base + "/api/command", payload);
var json = await resp.Content.ReadAsStringAsync();
payload := map[string]any{
    "cmd":       "TemplatePrint",
    "html":      t("<div>收件人:{{name}} {{addr}}</div>"),
    "data":      map[string]string{"name": t("张伟"), "addr": t("广州市天河区体育西路 100 号")},
    "printer":   "HP LaserJet Pro M404",
    "paperKind": "100x150",
}
b, _ := json.Marshal(payload)
resp, err := http.Post("http://127.0.0.1:19861/api/command",
                       "application/json", bytes.NewReader(b))
if err != nil { log.Fatal(err) }
defer resp.Body.Close()

Every language gets the same response body: Result JSON (code / error / data). On failure, always read error.

WebSocket /ws

Native WebSocket, sharing the same port as REST. The message body is the same as /api/command , returning the same Result structure; queue changes and other events are broadcast by the server.

const ws = new WebSocket("ws://127.0.0.1:19861/ws");
ws.onopen = () => ws.send(JSON.stringify({ cmd: "GetPrinterList" }));
ws.onmessage = (e) => {
  const result = JSON.parse(e.data);   // { code, error, data }
  console.log(result.code === 200 ? result.data : result.error);
};
# Requires: pip install websockets
import asyncio, json, websockets

async def main():
    async with websockets.connect("ws://127.0.0.1:19861/ws") as ws:
        await ws.send(json.dumps({"cmd": "GetPrinterList"}))
        result = json.loads(await ws.recv())
        print(result["data"] if result["code"] == 200 else result["error"])

asyncio.run(main())
using var ws = new ClientWebSocket();
await ws.ConnectAsync(new Uri("ws://127.0.0.1:19861/ws"), CancellationToken.None);
var body = Encoding.UTF8.GetBytes("{\"cmd\":\"GetPrinterList\"}");
await ws.SendAsync(body, WebSocketMessageType.Text, true, CancellationToken.None);
var buffer = new byte[8192];
var r = await ws.ReceiveAsync(buffer, CancellationToken.None);
Console.WriteLine(Encoding.UTF8.GetString(buffer, 0, r.Count));
// Requires: github.com/gorilla/websocket
c, _, err := websocket.DefaultDialer.Dial("ws://127.0.0.1:19861/ws", nil)
if err != nil { log.Fatal(err) }
defer c.Close()
c.WriteJSON(map[string]string{"cmd": "GetPrinterList"})
_, msg, _ := c.ReadMessage()
fmt.Println(string(msg))   // Result JSON

Use the long-lived connection when you need real-time notifications or batch sending, avoiding one HTTP round trip per command.

Notes per language

LanguageDescription
cURLNo dependencies; good for a first check of connectivity and endpoint availability
JavaScriptNative fetch and WebSocket in the browser or Node.js are all you need; no wrapper from this site
PythonThe standard-library urllib handles REST; WebSocket needs the websockets package
C#HttpClient / ClientWebSocket work out of the box — a good fit for Windows business systems
Gonet/http handles REST; gorilla/websocket is the common choice for WebSocket

Cross-network scenarios

When a terminal is not on the same subnet, it can connect out to the cloud service on its own, with jobs routed by device to the right printer; local print capability is unchanged.

  • How remote printing works: Remote printing
  • Scenario combinations: Examples
  • All endpoints: REST endpoint list
Overhead view of a shared development desk with laptops
Business systems can integrate from any language; the client only hands commands to the local printers