mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
Update example.cpp
This commit is contained in:
parent
576e287490
commit
8eceb3f7cc
30
example.cpp
30
example.cpp
@ -13,17 +13,12 @@ int main()
|
||||
return "Hello World!";
|
||||
});
|
||||
|
||||
FLASK_ROUTE(app, "/add_json")
|
||||
([](const flask::request& req){
|
||||
auto x = flask::json::load(req.body);
|
||||
if (!x)
|
||||
return flask::response(400);
|
||||
int sum = x["a"].i()+x["b"].i();
|
||||
std::ostringstream os;
|
||||
os << sum;
|
||||
return flask::response{os.str()};
|
||||
FLASK_ROUTE(app, "/about")
|
||||
([](){
|
||||
return "About Flask example.";
|
||||
});
|
||||
|
||||
// simple json response
|
||||
FLASK_ROUTE(app, "/json")
|
||||
([]{
|
||||
flask::json::wvalue x;
|
||||
@ -31,11 +26,6 @@ int main()
|
||||
return x;
|
||||
});
|
||||
|
||||
FLASK_ROUTE(app, "/about")
|
||||
([](){
|
||||
return "About Flask example.";
|
||||
});
|
||||
|
||||
FLASK_ROUTE(app,"/hello/<int>")
|
||||
([](int count){
|
||||
if (count > 100)
|
||||
@ -51,6 +41,18 @@ int main()
|
||||
//return flask::response(500);
|
||||
//});
|
||||
|
||||
// more json example
|
||||
FLASK_ROUTE(app, "/add_json")
|
||||
([](const flask::request& req){
|
||||
auto x = flask::json::load(req.body);
|
||||
if (!x)
|
||||
return flask::response(400);
|
||||
int sum = x["a"].i()+x["b"].i();
|
||||
std::ostringstream os;
|
||||
os << sum;
|
||||
return flask::response{os.str()};
|
||||
});
|
||||
|
||||
app.port(18080)
|
||||
.run();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user