1. demo
#include "crow.h"
int main()
{
crow::SimpleApp app;
CROW_ROUTE(app, "/")([](){
return "Hello world";
});
app.port(18080).multithreaded().run();
}
很熟悉的代码吧,和python flask库如此相像!
2. crow简介:
Crow is very fast and easy to use C++ micro web framework (inspired by Python Flask)
3. 特点:
Easy routing
Similiar to Flask
Type-safe Handlers-
Very Fast
You can also use json11 or rapidjson for better speed or readability
Mustache based templating library (crow::mustache)【html模板引擎】
Header only
Provide an amalgamated header file
crow_all.h
with every features (Download from here )Middleware support
Websocket support 【支持websocket】
4. 编译要求:
C++ compiler with good C++11 support (tested with g++>=4.8)
boost library【crow内部使用boost::asio异步文件流库】
CMake for build examples
Linking with tcmalloc/jemalloc is recommended for speed.【高效的c语言内存分配库,可以替换掉crt(c语言运行时)中的default实现】
Now supporting VS2013 with limited functionality (only run-time check for url is available.)【vs2013属于阉割版的c++11实现编译器,因此请使用vs2015或更高版本来编译crow库】
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();
std::ostringstream os;
os << sum;
return crow::response{os.str()};
});
5. 我的应用:
树莓派、嵌入式及乐高机器人视频专辑v0.1
集合中的第一篇视频有演示和为什么使用crow原因