Aegon

Usage & Quickstart

Getting started guide to building high-performance services with Aegon using modern C++23, CMake, C ABI, or Java.

This guide walks you through setting up your first project, building a microservice with Aegon, and running it with maximum hardware utilization.


1. Setting Up a C++23 CMake Project

Create a new directory for your project:

mkdir aegon-demo && cd aegon-demo

Create a CMakeLists.txt file configured for C++23 and linking against Aegon:

CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(aegon_demo CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find system-installed Aegon package
find_package(Aegon CONFIG REQUIRED)

# Define executable
add_executable(my_service src/main.cpp)

# Link Aegon modules (Aegon::http automatically pulls in Aegon::core and Aegon::net)
target_link_libraries(my_service PRIVATE
    Aegon::http
    Aegon::core
)

If you installed Aegon via .deb, .rpm, or Arch .pkg.tar.zst, CMake will find it automatically at /usr/lib/cmake/Aegon/AegonConfig.cmake. If installed to a custom prefix, pass -DCMAKE_PREFIX_PATH=/custom/path.


2. Writing Your First Service

Create src/main.cpp:

src/main.cpp
#include <aegon/http/Server.h>
#include <aegon/core/Task.h>
#include <aegon/http/middleware/AccessLog.h>
#include <aegon/http/middleware/Cors.h>
#include <iostream>

using namespace aegon;

// Request DTO with compile-time reflection
struct CreateUserRequest {
    std::string username;
    std::string email;
};

// Response DTO
struct UserResponse {
    uint64_t id;
    std::string username;
    std::string email;
    std::string status;
};

int main() {
    // 1. Initialize the HTTP Router
    http::Router router;

    // 2. Attach global middlewares
    router.use(http::middleware::AccessLogMiddleware());
    router.use(http::middleware::CorsMiddleware());

    // 3. Ultra-Fast Synchronous Endpoint (0 heap allocations, 0 coroutine frames)
    router.get("/health", [](http::Context& ctx) {
        ctx.res().status(http::StatusCode::Ok).text("OK");
    });

    // 4. Coroutine-based REST Endpoint with automatic JSON binding
    router.post("/api/v1/users", [](http::Context& ctx) -> core::Task<void> {
        // Automatically deserialize request body; emits 400 Bad Request on parse failure
        auto req = ctx.bind_json<CreateUserRequest>();
        if (!req) {
            co_return;
        }

        UserResponse res{
            .id = 42,
            .username = std::move(req->username),
            .email = std::move(req->email),
            .status = "active"
        };

        // Serialize response directly into output buffer
        ctx.res().status(http::StatusCode::Created).json(res);
        co_return;
    });

    // 5. Initialize Server and bind to port
    http::Server server(std::move(router));
    server.listen(8080, "0.0.0.0");

    // Optional: Enable HTTPS / HTTP/2 / HTTP/3
    // server.enable_tls("/path/to/cert.pem", "/path/to/key.pem");
    // server.listen(8443, http::Protocol::H1Tls | http::Protocol::H2 | http::Protocol::H3);

    std::cout << "Starting server on http://0.0.0.0:8080\n";

    // 6. Run event loop cluster pinned to all CPU cores
    server.run(std::thread::hardware_concurrency());
    return 0;
}

3. Compiling and Running

Build the executable using CMake and Ninja:

cmake -B build -S . -G Ninja
cmake --build build -j$(nproc)

Aegon always builds with -O3 -march=native; no build type is required.

Run the server:

./build/my_service

Test Endpoints

In another terminal, test the service using curl:

curl -i http://localhost:8080/health
HTTP/1.1 200 OK
content-type: text/plain
content-length: 2

OK

4. Pure C Application (C ABI)

Aegon provides a first-class C ABI (libaegon_c), allowing developers to write high-performance servers in pure C or integrate Aegon into other programming languages.

Create a main.c file:

main.c
#include <aegon/c/aegon.h>
#include <stdio.h>

void handle_root(aegon_context_t* ctx) {
    aegon_response_set_status(ctx, 200);
    aegon_response_set_body_text(ctx, "Hello from Pure C!");
}

int main(void) {
    aegon_router_t* router = aegon_router_create();
    aegon_router_get(router, "/", handle_root);

    aegon_server_t* server = aegon_server_create(router);
    aegon_server_listen(server, 8080, "0.0.0.0");
    // Optional: per-listener TLS / HTTP/2 / HTTP/3
    // aegon_server_enable_tls(server, "/path/to/cert.pem", "/path/to/key.pem");
    // aegon_server_listen_protocols(server, 8443, "0.0.0.0", AEGON_PROTO_H1_TLS | AEGON_PROTO_H2 | AEGON_PROTO_H3, NULL);

    printf("C server running on http://0.0.0.0:8080\n");
    aegon_server_run(server, 4);

    aegon_server_destroy(server);
    return 0;
}

Compile using pkg-config:

gcc main.c $(pkg-config --cflags --libs aegon-c) -o c_server
./c_server

5. Java 22+ Foreign Function & Memory (FFM)

Aegon provides native Java bindings built on Project Panama (FFM API) and virtual threads (Project Loom), achieving C-level HTTP performance inside the JVM without traditional JNI overhead.

HttpArena Verified Leader: The Aegon Java engine is ranked #1 in Java on the independent HttpArena benchmarks, delivering higher throughput and lower CPU cost than traditional JVM frameworks.

App.java
import com.teamzemo.aegon.AegonServer;
import com.teamzemo.aegon.AegonRouter;

public class App {
    public static void main(String[] args) {
        AegonRouter router = new AegonRouter();

        router.get("/hello", ctx -> {
            ctx.status(200).text("Hello from Aegon Java FFM!");
        });

        AegonServer server = new AegonServer(router);
        server.listen(8080, "0.0.0.0");
        // Optional: per-listener TLS / HTTP/2 / HTTP/3
        // server.enableTls("/path/to/cert.pem", "/path/to/key.pem");
        // server.listen(8443, Protocol.H1_TLS, Protocol.H2, Protocol.H3);

        System.out.println("Java Aegon server started on port 8080");
        server.run(Runtime.getRuntime().availableProcessors());
    }
}