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) {
|
||||
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<JSON_SIZE*8> jsonResponse;
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user