ipkn / crow

Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
BSD 3-Clause "New" or "Revised" License
7.46k stars 889 forks source link

Creating Crow server in Server class #376

Closed ezamosch closed 4 years ago

ezamosch commented 4 years ago

Hello.

I want to create Crow server in object oriented paradigm. Something like this:

class Server
{
public:
    Server(){
        Application = new crow::SimpleApp;
        Application->route("/", [&](const crow::request& req, crow::response& res) {
        return "index"});
    };
;
private:
    crow::SimpleApp* Application;

But I get error with route method of my Application method - "no instance of function template ...". Tell me please, how I supposed to property use route method properly to create route analogically to this:

CROW_ROUTE(Application, "/")([](const crow::request& req, crow::response& res) {
        return "index";
        });
mrozigor commented 4 years ago

CROW_ROUTE looks like this -> #define CROW_ROUTE(app, url) app.route<crow::black_magic::get_parameter_tag(url)>(url). Maybe try something like this: Application->route<crow::black_magic::get_parameter_tag("/")>("/")([&](const crow::request& req, crow::response& res) {return "index"});?

ezamosch commented 4 years ago

CROW_ROUTE looks like this -> #define CROW_ROUTE(app, url) app.route<crow::black_magic::get_parameter_tag(url)>(url). Maybe try something like this: Application->route<crow::black_magic::get_parameter_tag("/")>("/")([&](const crow::request& req, crow::response& res) {return "index"});?

On this case I get: image

mrozigor commented 4 years ago

Look into code ;) If you pass request and response object, then lambda can't return anything.

ezamosch commented 4 years ago

@mrozigor thank you 😊