Simple http server framework based on boost::asio, using C++11
- Easy to use
- Header only
- Boost::asio base
- Modern C++ (using C++11)
#include "server.hpp"
#include <string>
typedef std::shared_ptr<http::request> request_ptr;
int main() {
http::server app;
// simple text
app.route["^/helloworld/?$"]["GET"] = [](request_ptr req) {
return "<h1>Hello, world!</h1>";
};
// argument
app.route["^/hello/((.*)+)/?$"]["GET"] = [](request_ptr req) {
std::string name = req->path_match[1];
return "Hello," + name + "!";
};
// json
app.route["^/json/?$"]["GET"] = [](request_ptr req) {
http::json j;
j["message"] = "Hello, world!";
return j;
};
app.port(9913)
.threads(4)
.run();
return 0;
}