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.43k stars 889 forks source link

New feature: adding parametric url components as parameters to request #426

Open ClaudeTO80 opened 4 months ago

ClaudeTO80 commented 4 months ago

Hi all. I am trying, if possible, to create a generic approch for definition of routing rules.

Up to now parametric elements of URL can be defined and handled in such way, which works good _CROW_ROUTE(app, "/v2/hello/<int>").methods("GET"method)([&](const crow::request& req,int count) {...});

My request is if could be possible setting up another way for handling parametric elements of URL. Such approach would not require input arguments of called lambda matching to URL paramaters, but storing such parameters as key/value strings in request. A possible example could be

_CROW_ROUTE(app, "/v2/hello/<int>").url_params_names("firstParamName").methods("GET"method)([&](const crow::request& req) { ... std::string count = req.getUrlParam("firstParamName"); //getUrlParam or any other method name ... });

Such approach could be coupled with _routedynamic method which requires a parametric string known at runtime and not at compile time. This way routing information could be fully taken from a configuration file (example XML) and runtime function loaded at runtime from a shared library. Of course developer is in charge of handling correctly each detail of routing rules and function calls. As a result, it could be possibile splitting running application from routes definition. Routes could be dynamically added and removed only via configuration (e.g. XML) and keeping updated shared library of functions called.

My planes are using POCO C++ library for handling shared libraries and loading their symbols.

I hope my request is clear. Best things.