VWeb/example/main.cpp

38 lines
1.1 KiB
C++
Raw Normal View History

#include "VWeb-1.0/VWeb.h"
2022-08-23 14:13:21 +02:00
2022-11-09 14:34:20 +01:00
class MyCompleteController : public VWeb::Route {
public:
bool Get(VWeb::Request &req, VWeb::Response &response) override {
response << "MyCompleteController: GET:: \r\n\r\nParameters:\r\n\r\n";
for (auto &[key, value] : req.URLParameters) {
response << key << ": " << value << "\r\n";
}
2022-11-09 14:34:20 +01:00
return true;
}
bool Post(VWeb::Request &, VWeb::Response &response) override {
2022-11-09 14:34:20 +01:00
response << "MyCompleteController: POST";
return true;
}
};
bool Ping(const VWeb::Request &, VWeb::Response &response) {
2022-08-23 16:40:57 +02:00
response << "Pong";
return true;
}
2022-08-23 14:13:21 +02:00
int main() {
2022-08-23 16:40:57 +02:00
using namespace VWeb;
2022-08-23 14:13:21 +02:00
VWeb::Server server;
auto &router = server.GetRouter();
2023-09-02 14:17:56 +02:00
// For debugging and profiling more than 1 thread can be hard.
server.GetServerConfig()->WorkerThreads = 1;
router->Get("/test", [](Request &, Response &response) {
2022-08-23 16:40:57 +02:00
response << "NICE";
return true;
});
router->Get("/ping", &Ping);
router->Register<MyCompleteController>("/auth/:id/",
HttpMethod::GET | HttpMethod::POST);
2022-08-23 14:13:21 +02:00
server.Start();
server.Join();
return 0;
}