drogonframework / drogonframework/drogon
Noobie route question
- Dominant language
- C++
- Stars
- 14.3k
- Forks
- 1.4k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 15
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&& 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&& 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 });
```
Contributor guide
Assessment
This issue has not been assessed yet.