package mantra.web

Server

CLASS public class

HTTP server core for Mantra web applications, supporting worker concurrency, route mounting, and middleware pipelines.

🏗️ Constructor Summary

Constructor Signature
def __init__(self, config: ServerConfig)

⚙️ Method Summary

Modifier & Return Type Method Signature Description
Server pub def mount(prefix: String, router: Router) Mounts a router instance under the given base path prefix.
Void pub def listen() Binds the server socket to host and port and starts accepting incoming HTTP connections.
Server pub def with_middleware(chain: MiddlewareChain) Attaches a composable middleware execution pipeline to the server.

🔍 Detailed Method Specifications

pub def mount(prefix: String, router: Router) -> Server
Mounts a router instance under the given base path prefix.
pub def listen() -> Void
Binds the server socket to host and port and starts accepting incoming HTTP connections.
pub def with_middleware(chain: MiddlewareChain) -> Server
Attaches a composable middleware execution pipeline to the server.

💡 Example Usage

server_example.mantra
class MyApp:
    def __init__(self):
        self.config = ServerConfig("0.0.0.0", 8080, 4)

    pub def start(self):
        let router = Router()
        router.get("/", "home_handler")
        let server = Server(self.config)
        server.mount("/api", router)
        server.listen()