Skip to content

Instantly share code, notes, and snippets.

@deanberris
Created September 25, 2012 12:35
Show Gist options
  • Save deanberris/3781513 to your computer and use it in GitHub Desktop.
Save deanberris/3781513 to your computer and use it in GitHub Desktop.
HTTP Server Example
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