#include #include #include #include #include #include using namespace drogon; class A:public DrObjectBase { public: void handle(const HttpRequestPtr& req, const std::function&callback, int p1,const std::string &p2,const std::string &p3,int p4) const { HttpViewData data; data.insert("title",std::string("ApiTest::get")); std::map para; para["int p1"]=std::to_string(p1); para["string p2"]=p2; para["string p3"]=p3; para["int p4"]=std::to_string(p4); data.insert("parameters",para); auto res=HttpResponse::newHttpViewResponse("ListParaView",data); callback(res); } }; class B:public DrObjectBase { public: void operator ()(const HttpRequestPtr& req,const std::function&callback,int p1,int p2) { HttpViewData data; data.insert("title",std::string("ApiTest::get")); std::map para; para["p1"]=std::to_string(p1); para["p2"]=std::to_string(p2); data.insert("parameters",para); auto res=HttpResponse::newHttpViewResponse("ListParaView",data); callback(res); } }; namespace api { namespace v1 { class Test:public HttpApiController { public: METHOD_LIST_BEGIN METHOD_ADD(Test::get,"get/{2}/{1}","drogon::GetFilter");//path will be /api/v1/test/get/{arg2}/{arg1} METHOD_ADD(Test::list,"/{2}/info","drogon::GetFilter");//path will be /api/v1/test/{arg2}/info METHOD_LIST_END void get(const HttpRequestPtr& req,const std::function&callback,int p1,int p2) const { HttpViewData data; data.insert("title",std::string("ApiTest::get")); std::map para; para["p1"]=std::to_string(p1); para["p2"]=std::to_string(p2); data.insert("parameters",para); auto res=HttpResponse::newHttpViewResponse("ListParaView",data); callback(res); } void list(const HttpRequestPtr& req,const std::function&callback,int p1,int p2) const { HttpViewData data; data.insert("title",std::string("ApiTest::get")); std::map para; para["p1"]=std::to_string(p1); para["p2"]=std::to_string(p2); data.insert("parameters",para); auto res=HttpResponse::newHttpViewResponse("ListParaView",data); callback(res); } }; } } using namespace std::placeholders; int main() { std::cout<&callback,int a,float b){ LOG_DEBUG<<"int a="< para; para["a"]=std::to_string(a); para["b"]=std::to_string(b); data.insert("parameters",para); auto res=HttpResponse::newHttpViewResponse("ListParaView",data); callback(res); }); B b; //functor example drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle3/{1}/{2}",b); A tmp; std::function&,int,const std::string &,const std::string &,int)> func=std::bind(&A::handle,&tmp,_1,_2,_3,_4,_5,_6); //api example for std::function drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle4/{4}/{3}/{1}",func); drogon::HttpAppFramework::instance().setDocumentRoot("./"); //start app framework drogon::HttpAppFramework::instance().enableDynamicViewsLoading({"/tmp/views"}); drogon::HttpAppFramework::instance().run(); }