return list of commands as JSON array
This commit is contained in:
parent
73f7283918
commit
74f1dc1553
@ -32,10 +32,18 @@ namespace WebServer {
|
|||||||
});
|
});
|
||||||
|
|
||||||
server.on("/commands", HTTP_GET, [](AsyncWebServerRequest *request) {
|
server.on("/commands", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
string list;
|
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||||
for (auto it = Command::mapCommandIds.begin(); it != Command::mapCommandIds.end(); ++it)
|
|
||||||
list.append(it->first.c_str()).append("\n");
|
StaticJsonDocument<JSON_SIZE*8> jsonResponse;
|
||||||
request->send(200, "text/plain", list.c_str());
|
JsonArray array = jsonResponse.to<JsonArray>();
|
||||||
|
for (auto it = Command::mapCommandIds.begin(); it != Command::mapCommandIds.end(); ++it) {
|
||||||
|
StaticJsonDocument<JSON_SIZE/2> jsonDoc;
|
||||||
|
it->second->toJson(jsonDoc);
|
||||||
|
array.add(jsonDoc);
|
||||||
|
}
|
||||||
|
serializeJson(jsonResponse, *response);
|
||||||
|
|
||||||
|
request->send(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.onNotFound(notFound);
|
server.onNotFound(notFound);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user