File: HelloViewController.cc

package info (click to toggle)
drogon 1.9.11%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,820 kB
  • sloc: cpp: 57,270; sh: 297; xml: 20; makefile: 11
file content (29 lines) | stat: -rw-r--r-- 998 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <drogon/HttpSimpleController.h>
#include <drogon/HttpResponse.h>

using namespace drogon;

// HttpSimpleController does not allow registration of multiple handlers.
// Instead, it has one handler - asyncHandleHttpRequest. The
// HttpSimpleController is a lightweight class designed to handle really simple
// cases.
class HelloViewController : public HttpSimpleController<HelloViewController>
{
  public:
    PATH_LIST_BEGIN
    // Also unlike HttpContoller, HttpSimpleController does not automatically
    // prepend the namespace and class name to the path. Thus the path of this
    // controller is at "/view".
    PATH_ADD("/view");
    PATH_LIST_END

    void asyncHandleHttpRequest(
        const HttpRequestPtr &req,
        std::function<void(const HttpResponsePtr &)> &&callback) override
    {
        HttpViewData data;
        data["name"] = req->getParameter("name");
        auto resp = HttpResponse::newHttpViewResponse("HelloView", data);
        callback(resp);
    }
};