Crow
Crow copied to clipboard
Named route variables
I'm loving Crow so far, using it for a small project I am building which needs to wrap the Crow interface in order to expose it through my own means to Unreal Engine. I am trying to let users launch the server and create dynamic routes that can have a payload that gets automatically validated making use of the engines reflection system. I can't use static routes through the CROW_ROUTE macro due to limitation on how I am allowed to expose things to engine blueprints and stuff.
I am having a lot of problems trying to figure out how it would be possible to have named route variables in the manner of: /receive/:key
like other web frameworks I've used in the past. Then it would be so easy to fetch the data from the incoming const crow::request& request
in the handler lambda.
At the moment I am parsing this kind of syntax on my exposed functions and then converting it to a crow valid route such as /receive/<string>
, which then gets passed to route_dynamic(...)
.
The problem is that the handler lambda now expects me to manually declare a string parameter, which is hard to do when generating dynamic routes.
Wondering if there is a way to directly name the parameter in the route URL and then fetch it from const crow::request& request
instead?
If not, would this be a feature you are willing to implement in the near future?
Sadly I can't use other frameworks like Drogon since it works via a singleton instance that seems to not be possible to reinitialize at runtime. One of my requirements is to be able to constantly launch and reset the server instance.
Appreciate the help and advice.
If I understand this correctly, you want to use /url/<string>
but without defining a string parameter, instead fetching the parameter from the URL itself.
This is not a feature at the moment, but i can see its usefulness, and I would be willing to implement it.
Yes sorry if I was not clear.
I would want to be able to declare a named route variable on the url directly. In the form of ''/receive/:id'' or perhaps ''/receive/{id}''
This way I should be able to fetch the ''id'' param from the request data in the handler instead of having to specify a typed parameter.
Looks like reflection.
I just thought about this, why not just use url parameters instead and store your variables there?
@blessedbythestorm
I try this with catch_all
trie container
use crow "CROW_CATCHALL_ROUTE" and i put dynamic path with like this code block
registDynamicPathCallback("/depth1/{value_key_1}/depth2/{value_key_2}", [](const char* param) {
but it have bug with ssl cert.
not use ssl cert it can be work good with catch_all handler and redirect correct handler with extract variable {intext}
req.url: /depth1/123/depth2/qwer
it response expect
"value_key_1" : "123", "value_key_2" : "qwer"