🌍 a web framework for wren (fork of spiderwren)
Go to file
2024-02-07 02:57:37 +00:00
cmd initial fork 2024-02-07 00:54:31 +00:00
utils rm debug code 2024-02-07 02:57:37 +00:00
web read code, fix a bug 2024-02-07 02:50:55 +00:00
.gitattributes Remove Javascript from language stats 2021-04-08 18:26:49 -04:00
Dockerfile docker support 2021-04-17 21:14:39 -04:00
go.mod read code, fix a bug 2024-02-07 02:50:55 +00:00
go.sum read code, fix a bug 2024-02-07 02:50:55 +00:00
LICENSE Initial Commit 2021-04-08 08:26:17 -04:00
main.go initial fork 2024-02-07 00:54:31 +00:00
README.md read code, fix a bug 2024-02-07 02:50:55 +00:00
test.html read code, fix a bug 2024-02-07 02:50:55 +00:00
test.wren read code, fix a bug 2024-02-07 02:50:55 +00:00

wren-web

A web framework for Wren

installation

requirements: git & go 1.16+

$ git clone https://git.zvava.org/zvava/wren-web
$ cd wren-web
$ go get git.zvava.org/zvava/wren-web/cmd
$ go install

usage

index.wren

import "web" for Routes, App, Templates

Routes.GET("/") {
    return "hello"
}

Routes.GET("/param/*param") { | params |
    // /param/       → /
    // /param/hi     → /hi
    // /param/hi/lol → /hi/lol
    return params["param"]
}

Routes.GET("/add/:num1/:num2") { | params |
    var num1 = Num.fromString(params["num1"])
    var num2 = Num.fromString(params["num2"])

    return "%(num1) + %(num2) = %(num1 + num2)"
}

Routes.GET("/add/:num1/:num2/html") { | params |
    var num1 = Num.fromString(params["num1"])
    var num2 = Num.fromString(params["num2"])
    var res = num1 + num2

    return Templates.render("addition.html", {
        "num1": num1.toString,
        "num2": num2.toString,
        "result": r.toString
    })
}

App.run(3000)

addition.html

<!DOCTYPE html>
<html lang="en">
	<head><title>Addition</title></head>
	<body style="background: gray; color: pink;">{{num1}} + {{num2}} = {{result}}</body>
</html>

to start the application just run

$ wren-web start index.wren

in production

$ GIN_MODE=release wren-web start index.wren