aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLaurent Meyer <laurent@moid.de>2015-02-22 11:56:40 +0100
committerLaurent Meyer <laurent@moid.de>2015-02-22 11:56:40 +0100
commit4edc907fde52188df1cdd8bbca40a90dc0139cb1 (patch)
treec262decd3ed061ef63826b24cabbe359d42b3b2c /examples
parente08b9220e15ab30f4c1914d2191c693e60aec41d (diff)
downloadcrow-4edc907fde52188df1cdd8bbca40a90dc0139cb1.tar.gz
crow-4edc907fde52188df1cdd8bbca40a90dc0139cb1.zip
Added the comments for the param function because had problem to understand the pattern of lists in URL parameters
Diffstat (limited to 'examples')
-rw-r--r--examples/example.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/examples/example.cpp b/examples/example.cpp
index 87518fb..056fe6a 100644
--- a/examples/example.cpp
+++ b/examples/example.cpp
@@ -106,15 +106,27 @@ int main()
return crow::response{os.str()};
});
+ // Example of a request taking URL parameters
+ // If you want to activate all the functions just query
+ // {ip}:18080/params?foo='blabla'&pew=32&count[]=a&count[]=b
CROW_ROUTE(app, "/params")
([](const crow::request& req){
std::ostringstream os;
+
+ // To get a simple string from the url params
+ // To see it in action /param?foo='blabla'
os << "Params: " << req.url_params << "\n\n";
os << "The key 'foo' was " << (req.url_params.get("foo") == nullptr ? "not " : "") << "found.\n";
+
+ // To get a double from the request
+ // To see in action submit something like '/params?pew=42'
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';
}
+
+ // To get a list from the request
+ // You have to submit something like '/params?count[]=a&count[]=b' to have a list with two values (a and b)
auto count = req.url_params.get_list("count");
os << "The key 'count' contains " << count.size() << " value(s).\n";
for(const auto& countVal : count) {