代码拉取完成,页面将自动刷新
Crow is C++ microframework for web. Support Mac, Linux, windows, three platforms, the fastest development speed, the quickest and the strongest, the next step is to support ORM. At present, the performance of the framework should be ranked in the top five in the Techempower.
(inspired by Python Flask)[fork by Asciphx]
#include "cc.h"
int main(){
cc::SimpleApp app;
app["/"]([](){
return "Hello world!";
});
app.port(18080).multithreaded().run();
}
crow_all.h
with every features (Download from here) app.post("/upload")([](cc::Req& req) {
cc::Parser<2048> msg(req);
json j = json::object();
for (auto p : msg.params) {
if (!p.size) j[p.key] = p.value; else j[p.key] = p.filename;
}
return j;
});
app["/sql"]([] {
auto q = d.conn();
//std::tuple<int, std::string> ds=q("select id,name from users_test where id = 1").template r__<int,std::string>();
//std::cout<<std::get<0>(ds)<<std::get<1>(ds);
int i = 0; q("SELECT 200+2").r__(i);
std::string s; q("SELECT 'hello world'").r__(s);
return Res(i,s);
});
app["/list"]([]() {
User u; List list{ &u }; json::parse(list, R"({"user":{"is":false,"age":25,"weight":50.6,"name":"deaod"},
"userList":[{"is":true,"weight":52.0,"age":23,"state":true,"name":"wwzzgg"},
{"is":true,"weight":51.0,"name":"best","age":26}]})");
json json_output = json(list);
return json_output;
});
app.default_route()([] {
char name[64];gethostname(name,64);
json j{{"servername",name}};
return mustache::load("404NotFound.html").render(j);
});
app["/json"]([]{
cc::json x;
x["message"]="Hello, World!";
x["double"]=3.1415926;
x["int"]=2352352;
x["true"]=true;
x["false"]=false;
x["null"]=nullptr;
x["bignumber"]=2353464586543265455;
return x;
});
app["/hello/<int>"]([](int count){
if (count > 100) return cc::Res(400);
std::ostringstream os;
os << count << " bottles of beer!";
return cc::Res(os.str());
});
Handler arguments type check at compile time
// Compile error with message "Handler type is mismatched with URL paramters"
app["/another/<int>"]([](int a, int b){
return cc::Res(500);
});
app.post("/add_json")
([](cc::Req& req){
auto x = cc::json::load(req.body);
if (!x) return cc::Res(400);
int sum=x["a"].get<int>()+x["b"].get<int>();
std::ostringstream os;
os << sum;
return cc::Res{os.str()};
});
If you just want to use crow, copy amalgamate/cc_all.h and include it.
Out-of-source build with CMake is recommended.
mkdir build
cd build
cmake ..
make
You can run tests with following commands:
ctest
sudo apt-get install build-essential libtcmalloc-minimal4 && sudo ln -s /usr/lib/libtcmalloc_minimal.so.4 /usr/lib/libtcmalloc_minimal.so
brew install boost google-perftools
first install boost
second modify CmakeLists.txt
SET(BOOST_ROOT "E:/Code/boost_1_75_0") #Installation address of decompressed version
set(Boost_USE_STATIC_LIBS ON) #Support anything else
Crow uses the following libraries.
llhttp
https://github.com/nodejs/llhttp
Copyright Fedor Indutny, 2018.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
© 2021 GitHub, Inc.
qs_parse
https://github.com/bartgrantham/qs_parse
Copyright (c) 2010 Bart Grantham
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
TinySHA1
https://github.com/mohaps/TinySHA1
TinySHA1 - a header only implementation of the SHA1 algorithm. Based on the implementation in boost::uuid::details
Copyright (c) 2012-22 SAURAV MOHAPATRA mohaps@gmail.com
Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
json
https://github.com/nlohmann/json
Copyright (c) 2013-2021 Niels Lohmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。