Skip to content

rayquiro.web

The rayquiro.web module provides both a native embedded HTTP server for REST APIs and a declarative component templating system for rendering HTML web applications with zero external dependencies.

import "rayquiro.web";

1. Declarative Web Components & Templating

Section titled “1. Declarative Web Components & Templating”

In v1.1, rayquiro.web supports declarative element construction and templating without procedural nesting:

import "rayquiro.web";
var pageContent = web.element("div", {"class": "hero"}, [
web.element("h1", {"class": "title"}, "Fast, Native Web"),
web.element("p", {}, "Compiled directly to machine code"),
web.element("button", {"class": "primary-btn"}, "Get Started")
]);
web.page("Home", pageContent);
MethodSignatureDescription
web.elementweb.element(tag, props, children)Constructs a declarative element node object.
web.renderweb.render(tree)Recursively compiles a component tree or string into HTML.
web.templateweb.template(html, data)Interpolates a data dictionary into an HTML string with {{key}} syntax.
web.pageweb.page(title, body, [path], [css])Generates a single complete HTML page file directly.
web.beginweb.begin(title)Starts a multi-route static site build session.
web.routeweb.route(path, title)Defines a URL route and active page in static build.
web.endweb.end()Finalizes and writes all static pages to the build directory.
import "rayquiro.web";
var templateString = "<div class=\"user-card\"><h2>{{name}}</h2><span>Role: {{role}}</span></div>";
var card = web.template(templateString, {
"name": "RayQuiro Developer",
"role": "Core Maintainer"
});
web.render(card);

The HTTP server engine handles incoming TCP connections, parses HTTP/1.1 headers, and routes requests:

MethodSignatureDescription
web.serverweb.server()Creates a new HTTP server instance.
app.getapp.get(path, handler)Registers an HTTP GET route handler.
app.postapp.post(path, handler)Registers an HTTP POST route handler.
app.putapp.put(path, handler)Registers an HTTP PUT route handler.
app.deleteapp.delete(path, handler)Registers an HTTP DELETE route handler.
app.staticapp.static(prefix, dir)Serves static assets from a local folder.
app.listenapp.listen(port)Starts the server listening on the specified port.
app.stopapp.stop()Gracefully shuts down the web server.

Inside a route handler fn(req, res):

FieldTypeDescription
req.pathstringThe requested URL pathname.
req.methodstringHTTP verb ("GET", "POST", etc.).
req.bodystringRaw request body string.
req.headersobjectKey-value map of incoming HTTP headers.
req.queryobjectParsed query string parameters.
MethodSignatureDescription
res.sendres.send(text)Sends plain text with status 200.
res.htmlres.html(html)Sends HTML text with text/html; charset=utf-8.
res.jsonres.json(obj)Serializes object to JSON with application/json.
res.statusres.status(code)Sets the HTTP response status code.
res.headerres.header(name, val)Sets a custom response header.

import "rayquiro.web";
var app = web.server();
app.static("/public", "./public");
var items = [
{ id: 1, name: "Mechanical Keyboard", price: 120 },
{ id: 2, name: "Wireless Mouse", price: 65 }
];
app.get("/api/items", fn(req, res) {
res.json({ success: true, count: len(items), data: items });
});
app.post("/api/items", fn(req, res) {
try {
var payload = json.parse(req.body);
var new_item = {
id: len(items) + 1,
name: payload["name"],
price: payload["price"]
};
items.push(new_item);
res.status(201);
res.json({ success: true, item: new_item });
} catch (err) {
res.status(400);
res.json({ success: false, error: "Invalid JSON format" });
}
});
app.get("/", fn(req, res) {
res.html("<h1>RayQuiro Web Server</h1><p>Visit /api/items for REST data.</p>");
});
var port = 8080;
app.listen(port);
print("Web server running at http://localhost:" + str(port));