diff --git a/main.cpp b/main.cpp index c8e8f61..1e49c71 100644 --- a/main.cpp +++ b/main.cpp @@ -1,15 +1,18 @@ #include "request.hpp" #include "response.hpp" #include "router.hpp" + int main() { Router router(8080); + // Allow all Methods router.Handle("/helloWorld", [](Request req, Response res) -> Response { res.SetPayload("Hello World!"); res.SetContentType("text/plain"); return res; }); - + + // Only allow GET router.Handle("GET /echo/{name}", [](Request req, Response res) -> Response { std::string name = req.path.Get("name").value_or("No Name given"); res.SetPayload("Hello " + name); @@ -17,6 +20,7 @@ int main() { return res; }); + // Only allow POST router.Handle("POST /echo/{name}", [](Request req, Response res) -> Response { std::string name = req.path.Get("name").value_or("No Name given"); res.SetPayload("Hello with Post" + name); diff --git a/request.cpp b/request.cpp index 9f034ed..fa07695 100644 --- a/request.cpp +++ b/request.cpp @@ -24,7 +24,7 @@ bool Request::protocol(std::stringstream *ss, int *procPart, char c) { return true; } -// This is shit +// This is shit, meaning the path constructor Request::Request(std::vector buf) : path("") { std::string name; std::stringstream ss; diff --git a/response.cpp b/response.cpp index e069269..d0b1607 100644 --- a/response.cpp +++ b/response.cpp @@ -4,8 +4,6 @@ #include #include #include -#include -#include Response::Response(http::statusCode statusCode) { m_statusCode = statusCode; } diff --git a/router.cpp b/router.cpp index 2ce6d23..b1c34fb 100644 --- a/router.cpp +++ b/router.cpp @@ -1,12 +1,6 @@ #include "router.hpp" -#include // std::equal -#include // std::tolower #include -#include -#include // std::string_view #include -#include -#include Router::Router(int port) { m_socket = socket(AF_INET, SOCK_STREAM, 0);