hoeken/PsychicHttp

PsychicWebHandler questions

Closed this issue · 1 comments

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 PsychicWebHandler, but I really didn't understand if is it possible .. let me show the idea

class NewHandler: public PsychicWebHandler
{
public: 
       bool canHandle(PsychicRequest *request) override {
             return (request->url() == "/endpoint1" || request->url() == "/endpoint2");
       }  
        virtual esp_err_t handleRequest(PsychicRequest *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?

Yes this is possible. It's more maintainable to use the built-in functions, but this should work.