ESPAsyncWebServer icon indicating copy to clipboard operation
ESPAsyncWebServer copied to clipboard

Route ignore subpaths if root is added first

Open augustoeliezer opened this issue 5 years ago • 2 comments

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\"}"));
    });

augustoeliezer avatar Apr 29 '21 00:04 augustoeliezer

[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[bot] avatar Jun 28 '21 10:06 stale[bot]

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

stale[bot] avatar Jul 13 '21 00:07 stale[bot]