News for hackers. Stuff that matters.
Re:Show HN: Drogon – A C++14/17 based high performance HTTP ... by umvi on Tuesday March 19, 2019 @10:38AM (#19431172)
I like it, but the API for defining HTTP endpoints seems messy compared to, say, Flask or ExpressJS. Is there any particular reason it is done this way vs something syntactically cleaner, like:

    app.get("/test", [](drogon::Request & req, drogon::Response & res) {
        // Business Logic Goes Here?
    });
I'm going to be honest, I'm turned off by the macros and general API style of endpoint definition. I know, I know...

> Don't be scared by the code.

I can't help it!

Re:Show HN: Drogon – A C++14/17 based high performance HTTP ... by an-tao on Tuesday March 19, 2019 @10:58AM (#19431379)
You can register handler like this in Drogon:

   drogon::app.registerHttpMethod("/test",
                                   [=](const HttpRequestPtr& req,
                                       const std::function<void (const HttpResponsePtr &)> & callback)
                                   {
                                       Json::Value json;
                                       json["result"]="ok";
                                       auto resp=HttpResponse::newHttpJsonResponse(json);
                                       callback(resp);
                                   },
                                   {Get,"LoginFilter"});

The method in the readme file is for decoupling. Imagine a scene with dozens of path handlers. Isn't it better to disperse them in their respective classes?

Of course, for very simple logic, the interface you are talking about is really more intuitive, I will consider adding such an interface. Thank you for your comment.