| 21 | using router_t = rr::express_router_t<>; |
| 22 | |
| 23 | auto 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( |
| 55 | R"-(<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 | |
| 69 | int main( int argc, const char * argv[] ) |
| 70 | { |
no test coverage detected