#include "../../include/rapida.hxx" #include "../../include/servers/tcp.h" #include 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 = "" "" "Product" "" "

Product page

" "
";

        body += "Category: ";
        body += cat;
        body += "\n";

        body += "Id: ";
        body += id;

        body += "
" "" "\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; /* * `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 rpd_tcp_server_start(app.c_app(), "http://localhost:8080"); }