ESPAsyncWebServer
ESPAsyncWebServer copied to clipboard
Route ignore subpaths if root is added first
How /api/test is declared first, the others not work.
server->on("/api/test", HTTP_GET, [&](AsyncWebServerRequest *request) {
request->send(200, "application/json", F("{\"result\":\"c\"}"));
});
server->on("/api/test/a", HTTP_GET, [&](AsyncWebServerRequest *request) {
request->send(200, "application/json", F("{\"result\":\"a\"}"));
});
server->on("/api/test/b", HTTP_GET, [&](AsyncWebServerRequest *request) {
request->send(200, "application/json", F("{\"result\":\"b\"}"));
});
Expected
/api/test/a = {"result":"a"}
/api/test/b = {"result":"b"}
/api/test = {"result":"c"}
What returns - BUG
/api/test/a = {"result":"c"}
/api/test/b = {"result":"c"}
/api/test = {"result":"c"}
Workaround Move the more root url to the end.
server->on("/api/test/a", HTTP_GET, [&](AsyncWebServerRequest *request) {
request->send(200, "application/json", F("{\"result\":\"a\"}"));
});
server->on("/api/test/b", HTTP_GET, [&](AsyncWebServerRequest *request) {
request->send(200, "application/json", F("{\"result\":\"b\"}"));
});
//move this to the last
server->on("/api/test", HTTP_GET, [&](AsyncWebServerRequest *request) {
request->send(200, "application/json", F("{\"result\":\"c\"}"));
});
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.