-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
29 lines (24 loc) · 1.15 KB
/
Copy pathmain.cpp
File metadata and controls
29 lines (24 loc) · 1.15 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
#include <http_server/include/http_server.h>
#include <http_server/include/utils.h>
int main() {
using namespace http_server;
http_server::HttpServer server( 8090);
server.controlUrls["/api/v1/get"][http::verb::get] = [](auto& req , auto& res){
req.set( http::field::content_type, "text/html");
boost::beast::ostream(res.body()) <<
R"(<html><head><style>body{ background-color: #ede7f6 ;}h1 {text-align:center; color: #512da8;}
</style></head><body><h1>BOOST REST SERVER</h1></body></html>)";
};
server.controlUrls["/api/v1/echo-post"][http::verb::post] = [](auto& req , auto& res){
boost::beast::ostream(res.body()) << boost::beast::buffers_to_string(req.body().data());
};
server.controlUrls["/api/v1/user-agent"][http::verb::get] = [](auto& req , auto& res){
rapidjson::Document json;
json.SetObject();
json.AddMember( "client", req.at( http::field::user_agent).to_string(), json.GetAllocator() );
req.set( http::field::content_type, "application/json");
boost::beast::ostream(res.body()) << utils::jsonToString(json);
};
server.Run();
return 0;
}