From 8f11d069d438504856985cdee5ccaffa9e160e2a Mon Sep 17 00:00:00 2001 From: sha512sum Date: Sun, 7 Apr 2024 07:03:49 +0000 Subject: [PATCH] Add HTTPHandler example --- examples/http.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/http.cpp diff --git a/examples/http.cpp b/examples/http.cpp new file mode 100644 index 0000000..38b3ee5 --- /dev/null +++ b/examples/http.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +struct SomeComponent : public cserver::server::handlers::HTTPHandlerBaseWithAdder { + static constexpr utempl::ConstexprString kPath = "/v1/some/"; + static constexpr utempl::ConstexprString kName = "name"; + static constexpr utempl::ConstexprString kHandlerManagerName = "server"; + inline constexpr SomeComponent(auto name, auto& context) : + HTTPHandlerBaseWithAdder(name, context) {}; + + inline auto HandleRequestThrow(const cserver::server::http::HTTPRequest& request, + cserver::server::http::HTTPResponse&) -> cserver::Task { + co_return request.url.data(); + }; +}; + +auto main() -> int { + cserver::ServiceContextBuilder{} + .AppendConfigParam<"threads", 8>() + .AppendConfigParam<"server", cserver::ConstexprConfig{} + .Append<"taskProcessor">(utempl::ConstexprString{"basicTaskProcessor"}) + .Append<"port">(55555)>() + .Append>() + .Append() + .Sort() + .Run(); +};