ESPAsyncWebServer
ESPAsyncWebServer copied to clipboard
AsyncWebServerRequest Questions
hello.
I'm building a little framework for manage a complex automation, then the URIs are not gonna be the same every time.. then I was intending to use AsyncWebHandler, but I really didn't understand if is it possible .. let me show the idea
class NewHandler: public AsyncWebHandler
{
public:
bool canHandle(AsyncWebServerRequest *request) override {
return (request->url() == "/endpoint1" || request->url() == "/endpoint2");
}
virtual esp_err_t handleRequest(AsyncWebServerRequest *request) override{
if (request->url() == "/endpoint1")
{
return request->reply(200, "text/html", "called endpoint 1");
}
else
if (request->url() == "/endpoint2")
{
return request->reply(200, "text/html", "called endpoint 2");
}
else
{
return request->reply(404, "text/html", "endpoint not managed");
}
}
}
only add this class and do not use "server.on(...." to set endpoints is it possible? Is there any issue?
EDIT: Deleted because not applicable.
the problem i that I can't register handlers trough "server.on( ...", because the uris won't be the same every time .. for a better comprehension, there will be one main uri, like "/apiconfig" where i will register or remove addresses from the webserver. Then I was intending to do not register handlers, but use only one to manage all urls