Examples

Code That Ships and Works

Real examples you can copy, build, and run. Each example demonstrates specific Hype capabilities and includes instructions for building standalone executables.

🚀 Quick Start Examples

🖥️ Hello World TUI

Simple terminal application to get started

-- hello.lua
local app = tui.newApp()
local textView = tui.newTextView("Hello, World from Lua!")
app:SetRoot(textView, true)
app:Run()
Build & Run:
hype build hello.lua -o hello && ./hello
View Source

🌐 HTTP Server

Web server with JSON API endpoints

-- server.lua
local http = require('http')
local server = http.newServer()

server:handle("/", function(req, res)
    res:write("Hello from Hype server!")
end)

server:handle("/api/test", function(req, res)
    res:json({message = "API works!", time = os.time()})
end)

server:listen(8080)
Build & Run:
hype build server.lua -o server && ./server
View Source

🔐 Cryptography Examples

🔑 Basic Crypto Operations

Key generation, signing, and verification with multiple algorithms

-- Generate different types of keys
local rsa_key = crypto.generate_jwk("RS256")
local ecdsa_key = crypto.generate_jwk("ES256") 
local ed25519_key = crypto.generate_jwk("EdDSA")

-- Sign and verify messages
local message = "Hello, secure world!"
local signature = crypto.sign(rsa_key, message)
local public_key = crypto.jwk_to_public(rsa_key)
local is_valid = crypto.verify(public_key, message, signature)

🔏 HTTP Signatures

Secure API communication with request/response signing

-- Sign HTTP requests
local request = {
    type = "request",
    method = "POST",
    path = "/api/users",
    headers = { ["Host"] = "api.example.com" },
    body = '{"name": "Alice"}'
}

local signed = httpsig.sign(request, {
    jwk = client_key,
    key_id = "client-key-2024",
    headers = {"(request-target)", "host", "digest"}
})

🖥️ Interactive Applications

🌐 Text-based Web Browser

Terminal browser with HTML-to-text conversion and navigation

Features: URL navigation, HTML parsing, interactive interface

View Source

📊 Advanced Dashboard

Real-time monitoring dashboard with database integration

Features: TUI interface, HTTP server, database logging, real-time updates

View Source

📂 Complete Example Collection

Browse all examples in the GitHub repository. Each includes source code, build instructions, and usage examples.

🔧 How to Use Examples

# Clone the repo
git clone https://github.com/twilson63/hype.git
cd hype/examples

# Run an example directly
hype run hello.lua

# Build a standalone executable  
hype build hello.lua -o hello

# Run the executable (zero dependencies!)
./hello