cpp-httplib: How to get query parameters
This example shows how to get a query parameter in cpp-httplib. See the cpp-httplib hello example for the full source code:
get_query_param_cpp.cpp
svr.Get("/hi", [](const httplib::Request& req, httplib::Response& res) {
std::string id = req.get_param_value("id");
res.set_content("id=" + id, "text/plain");
});
Access it at http://localhost:8080/hi?id=myid
and it will show you
query_param_output.txt
id=myid
id
will be empty (== ""
) if no such parameter is given.
Check out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow