mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
support plain text POSTs to APIs
This commit is contained in:
@@ -51,6 +51,14 @@ void WebAPIService::webAPIService(AsyncWebServerRequest * request, JsonVariant j
|
||||
parse(request, input);
|
||||
}
|
||||
|
||||
// for POSTS accepting plain text data
|
||||
void WebAPIService::webAPIService(AsyncWebServerRequest * request, const char * data) {
|
||||
JsonDocument input_doc;
|
||||
JsonObject input = input_doc.to<JsonObject>();
|
||||
input["data"] = data;
|
||||
parse(request, input);
|
||||
}
|
||||
|
||||
#ifdef EMSESP_TEST
|
||||
// for test.cpp and unit tests so we can invoke GETs to test the API
|
||||
void WebAPIService::webAPIService(AsyncWebServerRequest * request) {
|
||||
@@ -113,6 +121,7 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) {
|
||||
|
||||
// call command
|
||||
uint8_t return_code = Command::process(request->url().c_str(), is_admin, input, output);
|
||||
|
||||
if (return_code != CommandRet::OK) {
|
||||
api_fails_++;
|
||||
}
|
||||
@@ -155,10 +164,19 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject input) {
|
||||
storeResponse(output);
|
||||
#endif
|
||||
#if defined(EMSESP_STANDALONE) && !defined(EMSESP_UNITY)
|
||||
Serial.printf("%sweb output: %s[%s]", COLOR_WHITE, COLOR_BRIGHT_CYAN, request->url().c_str());
|
||||
Serial.printf(" %s(%d)%s ", ret_codes[return_code] == 200 ? COLOR_BRIGHT_GREEN : COLOR_BRIGHT_RED, ret_codes[return_code], COLOR_YELLOW);
|
||||
serializeJson(output, Serial);
|
||||
Serial.println(COLOR_RESET);
|
||||
std::string output_str;
|
||||
serializeJson(output, output_str);
|
||||
Serial.printf("%sweb output: %s[%s] %s(%d)%s %s%s",
|
||||
COLOR_WHITE,
|
||||
COLOR_BRIGHT_CYAN,
|
||||
request->url().c_str(),
|
||||
ret_codes[return_code] == 200 ? COLOR_BRIGHT_GREEN : COLOR_BRIGHT_RED,
|
||||
ret_codes[return_code],
|
||||
COLOR_YELLOW,
|
||||
output_str.c_str(),
|
||||
COLOR_RESET);
|
||||
Serial.println();
|
||||
EMSESP::logger().debug("web output: %s %s", request->url().c_str(), output_str.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ class WebAPIService {
|
||||
WebAPIService(AsyncWebServer * server, SecurityManager * securityManager);
|
||||
|
||||
void webAPIService(AsyncWebServerRequest * request, JsonVariant input);
|
||||
void webAPIService(AsyncWebServerRequest * request, const char * data); // for plain text data
|
||||
|
||||
#if defined(EMSESP_TEST)
|
||||
// for test.cpp and running unit tests
|
||||
|
||||
Reference in New Issue
Block a user