From 74f1dc1553cd7a59c1774bc8060f133ecc940c3e Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 8 Sep 2025 12:21:10 +0200 Subject: [PATCH] return list of commands as JSON array --- src/webserver.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/webserver.h b/src/webserver.h index 4a0338c..ee58f14 100644 --- a/src/webserver.h +++ b/src/webserver.h @@ -32,10 +32,18 @@ namespace WebServer { }); server.on("/commands", HTTP_GET, [](AsyncWebServerRequest *request) { - string list; - for (auto it = Command::mapCommandIds.begin(); it != Command::mapCommandIds.end(); ++it) - list.append(it->first.c_str()).append("\n"); - request->send(200, "text/plain", list.c_str()); + AsyncResponseStream *response = request->beginResponseStream("application/json"); + + StaticJsonDocument jsonResponse; + JsonArray array = jsonResponse.to(); + for (auto it = Command::mapCommandIds.begin(); it != Command::mapCommandIds.end(); ++it) { + StaticJsonDocument jsonDoc; + it->second->toJson(jsonDoc); + array.add(jsonDoc); + } + serializeJson(jsonResponse, *response); + + request->send(response); }); server.onNotFound(notFound);