Update example.cpp

This commit is contained in:
ipkn 2014-04-26 07:44:09 +09:00
parent 576e287490
commit 8eceb3f7cc

View File

@ -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();
}