package mantra.rest

RouteHandler

CLASS public class

Typed route-to-handler registry and dispatcher for REST APIs with documentation descriptions.

🏗️ Constructor Summary

Constructor Signature
def __init__(self, method: String, path: String, handler: String, desc: String)

⚙️ Method Summary

Modifier & Return Type Method Signature Description
RouteHandler static def get(path: String, handler: String, desc: String) Constructs a GET route descriptor.
RouteHandler static def post(path: String, handler: String, desc: String) Constructs a POST route descriptor.
RouteHandler static def put(path: String, handler: String, desc: String) Constructs a PUT route descriptor.
RouteHandler static def delete(path: String, handler: String, desc: String) Constructs a DELETE route descriptor.

🔍 Detailed Method Specifications

static def get(path: String, handler: String, desc: String) -> RouteHandler
Constructs a GET route descriptor.
static def post(path: String, handler: String, desc: String) -> RouteHandler
Constructs a POST route descriptor.
static def put(path: String, handler: String, desc: String) -> RouteHandler
Constructs a PUT route descriptor.
static def delete(path: String, handler: String, desc: String) -> RouteHandler
Constructs a DELETE route descriptor.

💡 Example Usage

route_handler_example.mantra
let registry = RouteRegistry()
registry.register(RouteHandler.get("/api/v1/users", "get_users", "Fetch user list"))
registry.register(RouteHandler.post("/api/v1/users", "create_user", "Create new user"))

let res = registry.dispatch("GET", "/api/v1/users", req)