███╗ ██╗███████╗████████╗██╗ ██╗ ████╗ ██║██╔════╝╚══██╔══╝╚██╗██╔╝ ██╔██╗ ██║█████╗ ██║ ╚███╔╝ ██║╚██╗██║██╔══╝ ██║ ██╔██╗ ██║ ╚████║███████╗ ██║ ██║ ██║ ╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝ ╚═╝
NETX - High Performance Network Framework
#include "netx/http/response.hpp"
#include "netx/http/server.hpp"
#include <utility>
using namespace netx::http;
using namespace netx::net;
using namespace netx::async;
using namespace std::chrono_literals;
int main()
{
HttpServer::server()
.listen("127.0.0.1", 8080)
.route("GET", "/",
[](HttpRequest* req) -> Task<HttpResponse>
{
co_return std::move(HttpResponse{}
.status(200)
.content_type("text/html")
.body("<h1>Hello Netx</h1>"));
})
.timeout(3s)
.loop(8)
.start();
}.listen("127.0.0.1", 8080)binds the HTTP server to the local address and port..route("GET", "/", ...)registers a handler forGET /..timeout(3s)closes or times out idle connections after3s..loop(8)starts8worker event loops for request processing..start()launches the server.
You can configure logging with environment variables before starting the executable.
ELOG_PATH=/absolute/log/dir ELOG_LEVEL=INFO ./build/test/test1ELOG_PATH={dir}sets the log output directory. The directory must already exist.ELOG_LEVEL={TRACE, DEBUG, INFO, WARN, ERROR, FATAL}filters terminal log output only.- Async file logging is still written in full and is not affected by
ELOG_LEVEL.