#include #include #include #include #include #include #include std::string renderHTML(const std::string& title, const std::vector& messages) { std::ostringstream html; html << ' '; html << '' << title << ' '; html << ' '; html << '

' << title << '

'; for (const std::string& message : messages) { html << '

' << message << '

'; } html << ' '; return html.str(); } void handleGet(web::http::http_request request) { std::vector messages = {'Welcome to my C++ Web Service', 'Hello, World!'}; std::string htmlContent = renderHTML('C++ with HTML', messages); request.reply(web::http::status_codes::OK, htmlContent, 'text/html'); } int main() { web::http::experimental::listener::http_listener listener('http://localhost:6502'); listener.support(web::http::methods::GET, handleGet); try { listener.open().wait(); std::cout << 'Server is running on http://localhost:6502' << std::endl; while (true); } catch (std::exception const & e) { std::cerr << 'There was an error while setting up the HTTP listener: ' << e.what() << std::endl; } return 0; }