Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 950 Bytes

README.md

File metadata and controls

46 lines (36 loc) · 950 Bytes

asio

Simple http server framework based on boost::asio, using C++11

Build Status

Highlights

  • Easy to use
  • Header only
  • Boost::asio base
  • Modern C++ (using C++11)

Example

#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;
}