0

I'm having a problem handling requests on an ESP that acts as WebServer. Basically this code:

#include <WebServer.h> //using this library
...   
        webServer.on("/api/:userId/lights", HTTP_GET, [this]() { handle_GetState(); });
        webServer.on("/api/:userId/lights/:num", HTTP_GET, [this]() { handle_GetState(); });
        webServer.on("/api/:userId/lights/:num/state", HTTP_PUT, [this]() { handle_PutState(); });
        webServer.on("/", HTTP_GET, [this]() { handle_root(); });
        webServer.on("/debug/clip.html", HTTP_GET, [this]() { handle_clip(); });
        webServer.onNotFound( [this]() { handle_CORSPreflight(); });

is supposed to handle dynamic path parameters but when making a request (example: /api/USERXXX/lights) it's always handled by onNotFound function.

I've tried to replace ':userId' with '{}', '{userId}', '<userId>', but nothing seems to work. Obviously when calling http://192.168.XXX.XXX/api/:userId/lights the webserver retrieves the right response so the path parameter notation is not recognized.

Anyone knows which is the right way to do it?

  • 1
    https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WebServer/examples/PathArgServer/PathArgServer.ino – Juraj Mar 12 '23 at 15:33

0 Answers0