aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/example.cpp24
-rw-r--r--examples/example_chat.cpp2
2 files changed, 25 insertions, 1 deletions
diff --git a/examples/example.cpp b/examples/example.cpp
index 87518fb..dec57cd 100644
--- a/examples/example.cpp
+++ b/examples/example.cpp
@@ -62,7 +62,9 @@ int main()
return "Trailing slash test case..";
});
+
// simple json response
+ // To see it in action enter {ip}:18080/json
CROW_ROUTE(app, "/json")
([]{
crow::json::wvalue x;
@@ -70,6 +72,8 @@ int main()
return x;
});
+ // To see it in action enter {ip}:18080/hello/{integer_between -2^32 and 100} and you should receive
+ // {integer_between -2^31 and 100} bottles of beer!
CROW_ROUTE(app,"/hello/<int>")
([](int count){
if (count > 100)
@@ -79,6 +83,7 @@ int main()
return crow::response(os.str());
});
+ // To see it in action submit {ip}:18080/add/1/2 and you should receive 3 (exciting, isn't it)
CROW_ROUTE(app,"/add/<int>/<int>")
([](const crow::request& req, crow::response& res, int a, int b){
std::ostringstream os;
@@ -94,6 +99,13 @@ int main()
//});
// more json example
+
+ // To see it in action, I recommend to use the Postman Chrome extension:
+ // * Set the address to {ip}:18080/add_json
+ // * Set the method to post
+ // * Select 'raw' and then JSON
+ // * Add {"a": 1, "b": 1}
+ // * Send and you should receive 2
CROW_ROUTE(app, "/add_json")
.methods("POST"_method)
([](const crow::request& req){
@@ -106,15 +118,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 /params?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) {
diff --git a/examples/example_chat.cpp b/examples/example_chat.cpp
index aa7cc96..ae031b7 100644
--- a/examples/example_chat.cpp
+++ b/examples/example_chat.cpp
@@ -25,7 +25,7 @@ void broadcast(const string& msg)
}
ress.clear();
}
-
+// To see how it works go on {ip}:40080 but I just got it working with external build (not directly in IDE, I guess a problem with dependency)
int main()
{
crow::SimpleApp app;