68 {
70
72 std::cout << "Hier 1a ************" << std::endl;
73 std::cout << "Params: " << req->params["id"] << std::endl;
74 res->send("Done\n");
75 });
76
78 std::cout << "Hier 1b ************" << std::endl;
79 std::cout << "Params: " << req->params["id"] << std::endl;
80 std::cout << "Params: " << req->params["subcollection"] << std::endl;
81 res->send("Done\n");
82 });
83
85 std::cout << "Hier 2a ************" << std::endl;
86 std::cout << "Params: " << req->params["id"] << std::endl;
87 res->send("Done\n");
88 });
89
91 std::cout << "Hier 2b ************" << std::endl;
92 std::cout << "Params: " << req->params["id"] << std::endl;
93 std::cout << "Params: " << req->params["subcollection"] << std::endl;
94 res->send("Done\n");
95 });
96
98 std::cout << "Hier 3 ************" << std::endl;
99 std::cout << "Params: " << req->params["variable"] << std::endl;
100 std::cout << "Params: " << req->params["uri"] << std::endl;
101 res->send("Done\n");
102 });
103
106 "/query/:userId",
108 VLOG(1) << "Move on to the next route to query database";
109 next();
110 },
112 VLOG(1) << "UserId: " << req->params["userId"];
113 std::string userId = req->params["userId"];
114
115 req->setAttribute<std::string, "html-table">(std::string());
116
117 req->getAttribute<std::string, "html-table">([&userId](std::string& table) {
118 table = "<html>\n"
119 " <head>\n"
120 " <title>"
121 "Response from snode.c for " +
122 userId +
123 "\n"
124 " </title>\n"
125 " </head>\n"
126 " <body>\n"
127 " <h1>Return for " +
128 userId +
129 "\n"
130 " </h1>\n"
131 " <body>\n"
132 " <table border = \"1\">\n";
133 });
134
135 int i = 0;
137 "SELECT * FROM snodec where username = '" + userId + "'",
138 [next, req, i](const MYSQL_ROW row) mutable {
139 if (row != nullptr) {
140 i++;
141 req->getAttribute<std::string, "html-table">([row, &i](std::string& table) {
142 table.append(" <tr>\n"
143 " <td>\n" +
144 std::to_string(i) +
145 "\n"
146 " </td>\n"
147 " <td>\n" +
148 std::string(row[0]) +
149 "\n"
150 " </td>\n"
151 " <td>\n" +
152 row[1] +
153 "\n"
154 " </td>\n"
155 " </tr>\n");
156 });
157 } else {
158 req->getAttribute<std::string, "html-table">([](std::string& table) {
159 table.append(std::string(" </table>\n"
160 " </body>\n"
161 "</html>\n"));
162 });
163 VLOG(1) << "Move on to the next route to send result";
164 next();
165 }
166 },
167 [res, userId](const std::string& errorString, unsigned int errorNumber) {
168 VLOG(1) << "Error: " << errorString << " : " << errorNumber;
169 res->status(404).send(userId + ": " + errorString + " - " + std::to_string(errorNumber));
170 });
171 },
173 VLOG(1) << "And again 1: Move on to the next route to send result";
174 next();
175 },
177 VLOG(1) << "And again 2: Move on to the next route to send result";
178 next();
179 })
181 VLOG(1) << "And again 3: Move on to the next route to send result";
182 next();
183 })
185 VLOG(1) << "SendResult";
186
187 req->getAttribute<std::string, "html-table">(
188 [res](std::string& table) {
189 res->send(table);
190 },
191 [res](const std::string&) {
192 res->end();
193 });
194 });
196 VLOG(1) << "Show account of";
197 VLOG(1) << "UserId: " << req->params["userId"];
198 VLOG(1) << "UserName: " << req->params["userName"];
199
200 const std::string response = "<html>"
201 " <head>"
202 " <title>Response from snode.c</title>"
203 " </head>"
204 " <body>"
205 " <h1>Regex return</h1>"
206 " <ul>"
207 " <li>UserId: " +
208 req->params["userId"] +
209 " </li>"
210 " <li>UserName: " +
211 req->params["userName"] +
212 " </li>"
213 " </ul>"
214 " </body>"
215 "</html>";
216
217 const std::string userId = req->params["userId"];
218 const std::string userName = req->params["userName"];
219
221 "INSERT INTO `snodec`(`username`, `password`) VALUES ('" + userId + "','" + userName + "')",
222 [userId, userName]() {
223 VLOG(1) << "Inserted: -> " << userId << " - " << userName;
224 },
225 [](const std::string& errorString, unsigned int errorNumber) {
226 VLOG(1) << "Error: " << errorString << " : " << errorNumber;
227 });
228
229 res->send(response);
230 });
232 VLOG(1) << "Testing Regex";
233 VLOG(1) << "Regex1: " << req->params["testRegex1"];
234 VLOG(1) << "Regex2: " << req->params["testRegex2"];
235
236 const std::string response = "<html>"
237 " <head>"
238 " <title>Response from snode.c</title>"
239 " </head>"
240 " <body>"
241 " <h1>Regex return</h1>"
242 " <ul>"
243 " <li>Regex 1: " +
244 req->params["testRegex1"] +
245 " </li>"
246 " <li>Regex 2: " +
247 req->params["testRegex2"] +
248 " </li>"
249 " </ul>"
250 " </body>"
251 "</html>";
252
253 res->send(response);
254 });
256 VLOG(1) << "Show Search of";
257 VLOG(1) << "Search: " << req->params["search"];
258 VLOG(1) << "Queries: " << req->query("test");
259
260 res->send(req->params["search"]);
261 });
263 res->status(404).send("Not found: " + req->url);
264 });
265
267}
#define APPLICATION(req, res)
#define MIDDLEWARE(req, res, next)
MariaDBCommandSequence & exec(const std::string &sql, const std::function< void(void)> &onExec, const std::function< void(const std::string &, unsigned int)> &onError)
MariaDBCommandSequence & query(const std::string &sql, const std::function< void(const MYSQL_ROW)> &onQuery, const std::function< void(const std::string &, unsigned int)> &onError)
Route & use(const Router &router) const
Route & get(const Router &router) const