axil โ€” Complete API Reference

This document provides the exhaustive function reference, typedefs, server configuration flags, and hooks for axil. For a high-level overview, quickstart, and ecosystem context, see the main README.

Library API

Core Functions

FunctionDescriptionReturn Value
axil_main()Start event loop (blocking)Exit code
axil_register(name, cb, flags)Register command handler-
axil_register_handler(path, handler)Register HTTP handler for exact path or pattern-
axil_register_fallback_handler(handler)Register fallback HTTP handler (runs after all others declined)0 on success, -1 if full
axil_write(fd, data, len)Write raw bytesBytes written or -1
axil_writef(fd, fmt, ...)Write formatted dataBytes written or -1
axil_dwritef(fd, fmt, va)Write formatted data with va_listBytes written or -1
axil_close(fd)Close connection-
axil_wall(msg)Broadcast message to all descriptors-

HTTP Functions

FunctionDescriptionReturn Value
axil_header_set(fd, key, val)Add response header (call before axil_respond)-
axil_header_get(fd, key, buf, len)Get incoming request header0 on success, -1 if absent
axil_respond(fd, code, body)Send HTTP status, accumulated headers, optional body, and close when a body is provided-
axil_respond_plain(fd, status, msg)Send plain-text response with Content-Type: text/plain0 on 2xx
axil_redirect(fd, location)Send a 303 redirect0
axil_sendfile(fd, path)Serve static file with auto MIME type-
axil_status_text(code)Get HTTP status text for codeStatus string

axil_respond(), axil_sendfile(), built-in static files, and autoindex responses include cross-origin isolation headers by default. Static .wasm files are served as application/wasm.

WebSocket API

FunctionDescriptionReturn Value
axil_ws_handler(path, handler)Register WebSocket tunnel handler for a path-
axil_ws_upgrade(fd)Upgrade connection to WebSocket (handshake + connect hook)0 on success
axil_fd_watch(fd)Required after axil_ws_upgrade(); routes frames to axil_fd_tick()-
axil_ws_write(fd, data, len)Write data to WebSocketFrame size or -1
axil_ws_read(fd, buf, len)Read data from WebSocketBytes read, 0 on close, -1 on error
axil_ws_close(fd)Close WebSocket connection0 on success
axil_ws_printf(fd, fmt, ...)Formatted write to WebSocketWritten or -1

Server Configuration

struct axil_config {
    char *chroot;                     // chroot directory (POSIX)
    unsigned flags;                   // Server flags
    unsigned port;                    // HTTP listen port
    unsigned ssl_port;                // HTTPS listen port (POSIX)
    axil_handler_t *default_handler;  // Fallback HTTP handler
    size_t max_body_size;             // Max POST body size (0 = 10MB default)
};

Server Flags