diff --git a/lpstd.hpp b/lpstd.hpp index 37d9e9d..856e5ed 100644 --- a/lpstd.hpp +++ b/lpstd.hpp @@ -14,5 +14,6 @@ // #include "src/faker/faker.hpp" #include "src/exceptions/exceptions.hpp" #include "src/classes/command.hpp" +#include "src/classes/webserver.hpp" #endif // __LPSTD_HPP__ diff --git a/src/classes/webserver.hpp b/src/classes/webserver.hpp new file mode 100644 index 0000000..8635233 --- /dev/null +++ b/src/classes/webserver.hpp @@ -0,0 +1,92 @@ +#ifndef __LPSTD_WEBSERVER_H__ +#define __LPSTD_WEBSERVER_H__ + +#include "../patterns/singleton.hpp" +#include +#include +#include + + +namespace lpstd +{ + namespace classes + { + + namespace web + { + struct route + { + std::string path; + std::string method; + void (*func)(); + }; + } + + class WebServer : public lpstd::Singleton + { + + private: + std::vector routes = {}; + + public: + WebServer(/* args */) + { + } + ~WebServer() + { + } + + void addRoute(web::route route) + { + this->routes.push_back(route); + } + + void addRoute(std::string path, std::string method, void (*func)()) + { + web::route route = {path : path, method : method, func : func}; + this->routes.push_back(route); + } + + void get(std::string path, void (*func)()) + { + this->addRoute(path, "GET", func); + } + + void post(std::string path, void (*func)()) + { + this->addRoute(path, "POST", func); + } + + void put(std::string path, void (*func)()) + { + this->addRoute(path, "PUT", func); + } + + void patch(std::string path, void (*func)()) + { + this->addRoute(path, "PATCH", func); + } + + void del(std::string path, void (*func)()) + { + this->addRoute(path, "DELETE", func); + } + + void run(int port = 3000) + { + for (auto &route : this->routes) + { + std::cout << route.path << std::endl; + } + + std::cout << "Running on port " << port << std::endl; + + std::cout << "Listening..." << std::endl; + } + }; + + } // namespace classes + +} // namespace + +#endif // __LPSTD_WEBSERVER_H__ \ No newline at end of file