C and C++ web framework. http://rapida.vilor.one/docs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

#include "../../include/rapida.hxx"
#include <sstream>
class ProductRoute : public rpd::Route {
protected:
virtual void handle_get(const rpd::Request &req, rpd::Response &res) override
{
rpd::KeyVal params = req.params();
const char *cat = params["category"];
const char *id = params["id"];
std::string body = "<!DOCTYPE html>"
"<html>"
"<head><title>Product</title></head>"
"<body>"
"<h1>Product page</h1>"
"<pre>";
body += "Category: ";
body += cat;
body += "\n";
body += "Id: ";
body += id;
body += "</pre>"
"</body>"
"</html>\r\n";
handle_head(req, res);
res.body(body.c_str());
}
virtual void handle_head(const rpd::Request &req, rpd::Response &res) override
{
res.status(rpd_res_st_ok);
res.content_type("text/html");
}
};
int main()
{
rpd::App app("/tmp/rapida.example.socket");
/*
* `category` and `id` are dynamic parameters
* that can be found in the `params` field in `Route`.
*/
app.add_route("/products/:category/:id", new ProductRoute());
return app.start();
}