Update README.md

This commit is contained in:
An Tao 2019-03-19 23:21:14 +08:00 committed by GitHub
parent 34ebd7ef58
commit 9eb7025d74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -64,7 +64,23 @@ int main()
} }
``` ```
Drogon provides some interfaces for adding controller logic directly in the main() function, but unless your logic is very simple, we don't recommend using them. Instead, we create an HttpSimpleController as follows: Drogon provides some interfaces for adding controller logic directly in the main() function, for example, user can register a handler like this in Drogon:
```c++
app.registerHttpMethod("/test",
[=](const HttpRequestPtr& req,
const std::function<void (const HttpResponsePtr &)> & callback)
{
Json::Value json;
json["result"]="ok";
auto resp=HttpResponse::newHttpJsonResponse(json);
callback(resp);
},
{Get,"LoginFilter"});
```
In a scene with dozens of path handlers, isn't it better to disperse them in their respective classes? So unless your logic is very simple, we don't recommend using above interfaces. Instead, we create an HttpSimpleController as follows:
```c++ ```c++
/// The TestCtrl.h file /// The TestCtrl.h file