-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
Hi all,
I'm an absolute noobie with Drogon and need help with registerHandler, I need to register a handler that might have 2 or three parts to the route e.g
drogon::app().registerHandler(
"/{1}/{2}/{3}",
[&](const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& cb,
std::string c1,std::string c2, std::string c3)
{
std::string fullpath = req->getPath();
std::cout << "DISPATCH: " << fullpath << "\n";
drogon::HttpResponsePtr resp = global.Handle(fullpath, req, cb);
std::string_view body = resp->getBody();
std::cout << body << "\n";
}, { drogon::Get }
);
This is the only one I can get to work i.e it gets hit.
An example call would be (Postman) http://localhost:9657/clue/getcluebyid/123
I hope this makes sense and TIA
I figured it out
app.registerHandlerViaRegex(
"/.*",
[&](const drogon::HttpRequestPtr& req,
std::function<void(const drogon::HttpResponsePtr&)>&& cb)
{
std::string fullpath = req->getPath();
std::cout << "DISPATCH: " << fullpath << "\n";
resp = global.Handle(fullpath, req);
std::string_view respbody(resp->getBody());
cb(resp);
}, { drogon::Get ,drogon::Post });
Metadata
Metadata
Assignees
Labels
No labels