The WebExtension provides HTTP client, server, and WebSocket capabilities. Access via Net namespace.
# GET Request
response = Net.http_get("http://example.com");
# POST Request
response = Net.http_post("http://example.com/api", "{\\"key\\":\\"value\\"}");
You can start a lightweight web server (Javalin) to handle requests.
server = Net.Server();
# Register Handlers
server.get("/hello", "handle_hello");
server.post("/data", "handle_data");
# Start Server
server.start(8080);
Handler functions receive the request body as a string argument.
function handle_hello(body) {
return "Hello World!";
}
struct WsCallbacks {
function onConnect(ctx) { print("Connected"); }
function onMessage(ctx, msg) { print("Received: " + msg); ctx.send("Echo: " + msg); }
function onClose(ctx) { print("Closed"); }
function onError(ctx, err) { print("Error: " + err); }
}
callbacks = WsCallbacks();
server.ws("/ws", callbacks);
ws = Net.WebSocket();
ws.connect("ws://localhost:8080/ws", callbacks);
ws.send("Hello");
Simple template rendering using {{ key }} syntax.
structure Context { name; role; }
ctx = Context();
ctx.name = "Alice";
ctx.role = "Admin";
template = "User: {{ name }}, Role: {{ role }}";
html = Net.render(template, ctx);
# Result: "User: Alice, Role: Admin"