nx_moonraker_client.nx
buildroot/runtime/nx_moonraker_client.nx
about
nx_moonraker_client.nx -- request-construction layer for the
Klipper Moonraker HTTP API. Composes raw byte buffers that an
HTTP client (nx_http_client or nx_https_client) sends over a
socket to a Klipper printer's Moonraker server.
Per NISHI_3D_PRINT_BASELINE_2026_05_19 ยง3: Moonraker speaks HTTP
(file transfer + most endpoints) + JSON-RPC over WebSocket
(events). v1 of this primitive handles the HTTP slice:
GET /printer/info -- printer state
POST /printer/print/start -- start print from named file
POST /printer/print/cancel -- abort active print
POST /printer/objects/query -- subscribe to object updates
File upload (POST /server/files/upload multipart) deferred to v2;
for v1 the operator places the .gcode on the printer via scp/sftp
then calls /printer/print/start with the filename.
WebSocket event subscription deferred to v2; v1 uses HTTP polling
of /printer/objects/query. Moonraker explicitly supports both
(per https://moonraker.readthedocs.io/external_api/introduction).
API key handling:
Moonraker uses X-Api-Key header for authenticated requests.
v1 accepts an api_key parameter at construction time and adds
the header to every request when non-NULL.
JSON safety:
v1 assumes filenames contain only [a-zA-Z0-9._-/]. Quotes and
backslashes in user filenames will break the JSON. v2 will
compose nx_json_emit (already shipped) for proper escaping.
Per cardinal feedback-engineering-sciences-bits-up-3d-print-first:
this primitive is one of the FIRST examples of substrate primitives
composing into a real device-control workflow (operator -> substrate
-> printer over network). Same pattern will apply to nx_cnc_client
(Mach3 / LinuxCNC), nx_voron_klipper (variant), nx_marlin_serial
(older firmware), etc.
license_tier: ORIGINAL
dependencies 1 imports · 12 importers
diagram shows first 10 each side; +0 more imports, +2 more importers in the complete lists below.
imports: nx_syscalls.nx
imported by: nx_monitor_html.nxnx_monitor_html_test.nxnx_moonraker_client_test.nxnx_moonraker_io.nxnx_moonraker_io_ipv4_test.nxnx_moonraker_io_test.nxnx_moonraker_ready_check.nxnx_moonraker_ready_check_test.nxnx_print_e2e_test.nxnx_print_response.nxnx_printer_ctl_gate.nxnx_printer_ctl_lib.nx
structs
| none |
consts
| 45 | const NX_MR_OK: i64 = 0 |
| 46 | const NX_MR_ERR_OVERFLOW: i64 = 1 |
| 47 | const NX_MR_ERR_BAD_INPUT: i64 = 2 |
| 48 | const NX_MR_ERR_BAD_FILENAME: i64 = 3 |
| 49 | const NX_MR_N_VERDICTS: i64 = 4 |
functions
| 51 | func nx_mr_verdict_name(v: i64) -> *u8 |
| 62 | func nx_mr_write_bytes(dst: *u8, off: i64, cap: i64, |
| 74 | func nx_mr_write_cstr(dst: *u8, off: i64, cap: i64, s: *u8) -> i64 |
| 87 | func nx_mr_write_int(dst: *u8, off: i64, cap: i64, value: i64) -> i64 |
| 128 | func nx_mr_filename_is_safe(fn: *u8, fn_len: i64) -> i64 |
| 155 | func nx_mr_build_url(base: *u8, base_len: i64, calls 1: nx_mr_write_bytes |
| 173 | func nx_mr_build_print_start_body(filename: *u8, fn_len: i64, called by 4: mainmainmainpctl_printstart calls 3: nx_mr_filename_is_safenx_mr_write_cstrnx_mr_write_bytes |
| 195 | func nx_mr_build_post_request(host: *u8, host_len: i64, |
| 233 | func nx_mr_build_get_request(host: *u8, host_len: i64, |
| 261 | func nx_mr_parse_status(resp: *u8, resp_len: i64) -> i64 |