This commit is contained in:
2026-01-24 23:40:22 +01:00
parent 1a0f7f51a1
commit 8c1a721c4c
105 changed files with 23275 additions and 94 deletions
+19
View File
@@ -0,0 +1,19 @@
// retoor <retoor@molodetz.nl>
import "web" for Response
var r1 = Response.text("Hello")
System.print(r1.body) // expect: Hello
System.print(r1.headers["Content-Type"].contains("text/plain")) // expect: true
var r2 = Response.html("<h1>Hi</h1>")
System.print(r2.body) // expect: <h1>Hi</h1>
System.print(r2.headers["Content-Type"].contains("text/html")) // expect: true
var r3 = Response.json({"name": "test"})
System.print(r3.body.contains("name")) // expect: true
System.print(r3.headers["Content-Type"].contains("application/json")) // expect: true
var r4 = Response.redirect("/login")
System.print(r4.status) // expect: 302
System.print(r4.headers["Location"]) // expect: /login
+21
View File
@@ -0,0 +1,21 @@
// retoor <retoor@molodetz.nl>
import "web" for Router
var router = Router.new()
router.get("/", Fn.new { |r| "home" })
router.get("/users/:id", Fn.new { |r| "user" })
router.post("/api/data", Fn.new { |r| "data" })
var m1 = router.match("GET", "/")
System.print(m1 != null) // expect: true
var m2 = router.match("GET", "/users/123")
System.print(m2 != null) // expect: true
System.print(m2["params"]["id"]) // expect: 123
var m3 = router.match("POST", "/api/data")
System.print(m3 != null) // expect: true
var m4 = router.match("GET", "/notfound")
System.print(m4 == null) // expect: true
+19
View File
@@ -0,0 +1,19 @@
// retoor <retoor@molodetz.nl>
import "web" for SessionStore
var store = SessionStore.new()
var session = store.create()
System.print(session.id != null) // expect: true
System.print(session.id.count) // expect: 36
session["user"] = "alice"
System.print(session["user"]) // expect: alice
store.save(session)
var retrieved = store.get(session.id)
System.print(retrieved != null) // expect: true
System.print(retrieved["user"]) // expect: alice
store.destroy(session.id)
System.print(store.get(session.id) == null) // expect: true