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);