MCPcopy Create free account
hub / github.com/Stiffstream/restinio / server_handler

Function server_handler

dev/sample/hello_world_https/main.cpp:23–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21using router_t = rr::express_router_t<>;
22
23auto server_handler()
24{
25 auto router = std::make_unique< router_t >();
26
27 router->http_get(
28 "/",
29 []( auto req, auto ){
30 init_resp( req->create_response() )
31 .append_header( restinio::http_field::content_type, "text/plain; charset=utf-8" )
32 .set_body( "Hello world!")
33 .done();
34
35 return restinio::request_accepted();
36 } );
37
38 router->http_get(
39 "/json",
40 []( auto req, auto ){
41 init_resp( req->create_response() )
42 .append_header( restinio::http_field::content_type, "application/json" )
43 .set_body( R"-({"message" : "Hello world!"})-")
44 .done();
45
46 return restinio::request_accepted();
47 } );
48
49 router->http_get(
50 "/html",
51 []( auto req, auto ){
52 init_resp( req->create_response() )
53 .append_header( restinio::http_field::content_type, "text/html; charset=utf-8" )
54 .set_body(
55R"-(<html>
56<head><title>Hello from RESTinio!</title></head>
57<body>
58<center><h1>Hello world</h1></center>
59</body>
60</html>)-" )
61 .done();
62
63 return restinio::request_accepted();
64 } );
65
66 return router;
67}
68
69int main( int argc, const char * argv[] )
70{

Callers 1

mainFunction · 0.70

Calls 5

request_acceptedFunction · 0.85
create_responseMethod · 0.80
init_respFunction · 0.70
http_getMethod · 0.45
doneMethod · 0.45

Tested by

no test coverage detected