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.
|
|
|
#include "../../include/rapida.hxx"
|
|
|
|
#include "../../include/servers/tcp.h"
|
|
|
|
#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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* `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");
|
|
|
|
}
|