-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (43 loc) · 1.3 KB
/
main.cpp
File metadata and controls
48 lines (43 loc) · 1.3 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "src/rest/Defines.hpp"
#include "src/rest/HttpClientRequest.hpp"
#include "src/server/BasicServer.hpp"
#include "src/server/HttpServer.hpp"
#include "src/utils/HtmlBuilder.hpp"
#include <EssaUtil/Json.hpp>
#include <iostream>
#include <sstream>
#include <string_view>
#include <vector>
int main(){
HttpServer server;
server.set_port(2137);
server.add_get_method("/", [](const HttpGETClientRequest&) -> HttpServerResponse{
return HttpServerResponse::text(OK, "Working!");
});
server.add_get_method("/xd", [](const HttpGETClientRequest&) -> HttpServerResponse{
JSON::Node json({
{"abc", 1},
{"def", true},
{"ghi", JSON::Array({
1,
"cos",
JSON::Node({
{"aaa", false}
})
})},
{"jkl", JSON::Node({
{"mno", 2.5}
})}
});
return HttpServerResponse::json(OK, json);
});
server.add_get_method("/bajojajo", [](const HttpGETClientRequest& req) -> HttpServerResponse{
std::stringstream ss;
for(const auto& g : req.Get()){
ss << g.first << " -> " << g.second << "\n";
}
return HttpServerResponse::text(OK, ss.str());
});
server.run();
return 0;
}