1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
//[ simple_http_server
#include <zeep/http/server.hpp>
#include <zeep/http/controller.hpp>
class hello_controller : public zeep::http::controller
{
public:
/*<< Specify the root path as prefix, will handle any request URI >>*/
hello_controller() : controller("/") {}
bool handle_request(zeep::http::request& req, zeep::http::reply& rep)
{
/*<< Construct a simple reply with status OK (200) and content string >>*/
rep = zeep::http::reply::stock_reply(zeep::http::ok);
rep.set_content("Hello", "text/plain");
return true;
}
};
int main()
{
zeep::http::server srv;
srv.add_controller(new hello_controller());
srv.bind("::", 8080);
srv.run(2);
return 0;
}
//]
|