Skip to content

Noobie route question #2412

@pkfox

Description

@pkfox

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions