Hello World
Hello World
Section titled “Hello World”Your first Wippy application - a simple HTTP API that returns JSON.
What We’re Building
Section titled “What We’re Building”A minimal web API with one endpoint:
GET /hello → {"message": "hello world"}Project Structure
Section titled “Project Structure”hello-world/├── wippy.lock # Generated lock file└── src/ ├── _index.yaml # Entry definitions └── hello.lua # Handler codeStep 1: Create Project Directory
Section titled “Step 1: Create Project Directory”mkdir hello-world && cd hello-worldmkdir srcStep 2: Entry Definitions
Section titled “Step 2: Entry Definitions”Create src/_index.yaml:
version: "1.0"namespace: app
entries: # HTTP server - name: gateway kind: http.service addr: ":8080" lifecycle: auto_start: true
# Router - name: api kind: http.router meta: server: app:gateway prefix: /
# Handler function - name: hello kind: function.lua source: file://hello.lua method: handler modules: - http
# Endpoint - name: hello.endpoint kind: http.endpoint meta: router: app:api method: GET func: app:hello path: /helloFour entries work together:
gateway- HTTP server listening on port 8080api- Router attached to gateway viameta.serverhello- Lua function that handles requestshello.endpoint- RoutesGET /helloto the function
Step 3: Handler Code
Section titled “Step 3: Handler Code”Create src/hello.lua:
local http = require("http")
local function handler() local res = http.response()
res:set_content_type(http.CONTENT.JSON) res:set_status(http.STATUS.OK) res:write_json({message = "hello world"})end
return { handler = handler}The http module provides access to request/response objects. The function returns a table with the exported handler method.
Step 4: Initialize and Run
Section titled “Step 4: Initialize and Run”# Generate lock file from sourcewippy init
# Start the runtime (-c for colorful console output)wippy run -cYou’ll see output like:
╦ ╦╦╔═╗╔═╗╦ ╦ Adaptive Application Runtime║║║║╠═╝╠═╝╚╦╝ v0.1.20╚╩╝╩╩ ╩ ╩ by Spiral Scout
0.00s INFO run runtime ready0.11s INFO core service app:gateway is running {"details": "service listening on :8080"}Step 5: Test It
Section titled “Step 5: Test It”curl http://localhost:8080/helloResponse:
{"message":"hello world"}How It Works
Section titled “How It Works”gatewayaccepts the TCP connection on port 8080apirouter matches the path prefix/hello.endpointmatchesGET /hellohellofunction executes and writes JSON response
CLI Reference
Section titled “CLI Reference”| Command | Description |
|---|---|
wippy init | Generate lock file from src/ |
wippy run | Start runtime from lock file |
wippy run -c | Start with colorful console output |
wippy run -v | Start with verbose debug logging |
wippy run -s | Start in silent mode (no console logs) |
Next Steps
Section titled “Next Steps”- Echo Service - Handle request parameters
- Task Queue - REST API with background processing
- HTTP Router - Routing patterns