aboutsummaryrefslogtreecommitdiffstats
path: root/examples/example.cpp
diff options
context:
space:
mode:
authoripkn <ipknhama@gmail.com>2014-10-23 23:44:31 +0900
committeripkn <ipknhama@gmail.com>2014-10-23 23:44:31 +0900
commit4965d495a7ada4fb7c6aeed1fd6c4b5830bb99a9 (patch)
treea65f112b1df3035807c3b5dfab9aca86d86d1d1e /examples/example.cpp
parenta5fab23f70e6e33c633ba4b646a41d0851169ad1 (diff)
parentada303970732f00e2d3017b726effad65d27a4d2 (diff)
downloadcrow-4965d495a7ada4fb7c6aeed1fd6c4b5830bb99a9.tar.gz
crow-4965d495a7ada4fb7c6aeed1fd6c4b5830bb99a9.zip
Merge pull request #28 from acron0/url-params-in-req
Added URL params (request.url_params)
Diffstat (limited to 'examples/example.cpp')
-rw-r--r--examples/example.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/examples/example.cpp b/examples/example.cpp
index b360adb..d7a4736 100644
--- a/examples/example.cpp
+++ b/examples/example.cpp
@@ -5,7 +5,7 @@
class ExampleLogHandler : public crow::ILogHandler {
public:
- void log(string message, crow::LogLevel level) override {
+ void log(std::string message, crow::LogLevel level) override {
// cerr << "ExampleLogHandler -> " << message;
}
};
@@ -68,8 +68,25 @@ int main()
return crow::response{os.str()};
});
+ CROW_ROUTE(app, "/params")
+ ([](const crow::request& req){
+ std::ostringstream os;
+ os << "Params: " << req.url_params << "\n\n";
+ os << "The key 'foo' was " << (req.url_params.get("foo") == nullptr ? "not " : "") << "found.\n";
+ if(req.url_params.get("pew") != nullptr) {
+ double countD = boost::lexical_cast<double>(req.url_params.get("pew"));
+ os << "The value of 'pew' is " << countD << '\n';
+ }
+ auto count = req.url_params.get_list("count");
+ os << "The key 'count' contains " << count.size() << " value(s).\n";
+ for(const auto& countVal : count) {
+ os << " - " << countVal << '\n';
+ }
+ return crow::response{os.str()};
+ });
+
// ignore all log
- crow::logger::setLogLevel(crow::LogLevel::CRITICAL);
+ crow::logger::setLogLevel(crow::LogLevel::DEBUG);
//crow::logger::setHandler(std::make_shared<ExampleLogHandler>());
app.port(18080)