-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
33 lines (28 loc) · 809 Bytes
/
Copy pathmain.cpp
File metadata and controls
33 lines (28 loc) · 809 Bytes
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
30
31
32
33
#include <iostream>
#include "HttpServer.h"
int main() {
HttpServer server{};
server.get_mapping(
"/test", [](HttpServer::Request &req, HttpServer::Response &res) {
res.body = "testing new api route";
});
server.post_mapping(
"/test2/{id}/foo/{user}",
[](HttpServer::Request &req, HttpServer::Response &res) {
std::stringstream ss;
try {
ss << "{\"id\":" << "\"" << req.path_params.get_path_param("id").value() << "\","
<< "\"user\":" << "\"" << req.path_params.get_path_param("user").value() << "\""
<< "}";
res.body = ss.str();
} catch (const std::bad_optional_access &e) {
res.body = "could not get path parameter";
}
});
try {
server.listen(3490);
} catch (const std::exception &err) {
std::cerr << err.what() << '\n';
return EXIT_FAILURE;
}
}