cinatra框架

cinatra框架是一个C++ Web App框架

cd ~
git clone https://github.com/qicosmos/cinatra.git
cd ~
mkdir -p cinatra-app/first
cd cinatra-app/first
touch main.cpp

在main.cpp中写入以下代码

#include <iostream>
using namespace std;

#include "../../cinatra/http_server.hpp"
using namespace cinatra;

int main()
{
    int max_thread_num = std::thread::hardware_concurrency();
    cout << max_thread_num << endl;
    http_server server(max_thread_num);
    server.listen("0.0.0.0", "8081");

    server.set_http_handler<GET, POST>("/", [](const request& req, response& res) {
        res.set_status_and_content(status_type::ok, "hello world");
    });

    server.run();
    return 0;
}

然后编译

g++ main.cpp -std=c++17 -lboost_system -lpthread

标签: none

添加新评论