Crow有一个很有意思的实现,就是绑定url时的参数可以跟处理lambda的类型自动匹配
CROW_ROUTE(app, "/hello/<int>")
([](int count) {
if (count > 100)
return crow::response(400);
std::ostringstream os;
os << count << " bottles of beer!";
return crow::response(os.str());
});
CROW_ROUTE(app, "/add/<int>/<int>")
([](crow::response& res, int a, int b) {
std::ostringstream os;
os << a + b;
res.write(os.str());
res.end();
});
CROW_ROUTE(app, "/add_json")
.methods("POST"_method)([](const crow::request& req) {
auto x = crow::json::load(req.body);
if (!x)
return crow::response(400);
int sum = x["a"].i() + x["b"].i();
st