Created
September 25, 2012 12:35
-
-
Save deanberris/3781513 to your computer and use it in GitHub Desktop.
HTTP Server Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace http = network::http; | |
http::server server_; | |
server_.register_handler( | |
"/hello", [](session& s, std::shared_ptr<connection> c) { | |
c->response().write(s["user"].empty()? string("world!") : s["user"]); | |
}); | |
server_.register_handler( | |
"/echo", [](session& s, std::shared_ptr<connection> c) { | |
if (c->method() != http::server::POST) { | |
c->response().write("echo!"); | |
return; | |
} | |
c->data().read(getpagesize(), [c](const std::string& data) { | |
if (!data.empty()) | |
c->response().write(data); | |
}); | |
}); | |
s.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment