Skip to content
app.routes 1.42 KiB
Newer Older
theMackabu's avatar
theMackabu committed
index {
theMackabu's avatar
theMackabu committed
   text(":3\nwelcome to the root")
}

hello() {
theMackabu's avatar
theMackabu committed
   response("Hello World!", "text", 200)
theMackabu's avatar
theMackabu committed
}

theMackabu's avatar
theMackabu committed
#[route("/example")]
theMackabu's avatar
theMackabu committed
example() {
theMackabu's avatar
theMackabu committed
   html(http::get("https://example.org").body)
theMackabu's avatar
theMackabu committed
}

theMackabu's avatar
theMackabu committed
#[route("/db")]
db() {
   let db = kv::load("test.db");
   
   db.set("some.key", json::dump(#{name: "John", id: 50}));
   let data = json::parse(db.get("some.key"));
   
   json(data)
}

#[route("/example/{id}.txt")]
theMackabu's avatar
theMackabu committed
example(id) {
   text("base: " + id)
}

#[route("/example/{id}/test")]
theMackabu's avatar
theMackabu committed
example_test(id) {
   text("sub: " + id)
}

#[route("/name/{id}/{name}")]
name(id, name) {
   json(#{name: name, id: id})
theMackabu's avatar
theMackabu committed
}

theMackabu's avatar
theMackabu committed
example/json() {
   let res = http::get("https://httpbin.org/json");
theMackabu's avatar
theMackabu committed
   let body = #{ 
theMackabu's avatar
theMackabu committed
      response: res.json(),
theMackabu's avatar
theMackabu committed
      info: #{
         length: res.length,
         status: res.status,
         error: res.error,
         body: res.body,
theMackabu's avatar
theMackabu committed
      },
theMackabu's avatar
theMackabu committed
   };
   
   json(body)
}

example/post/bin() {
theMackabu's avatar
theMackabu committed
   let body = #{ 
      hello: "world",
      url: url,
   };
   
   json(http::post("https://httpbin.org/post", body).raw())
theMackabu's avatar
theMackabu committed
}
theMackabu's avatar
theMackabu committed

theMackabu's avatar
theMackabu committed
test.json() {
theMackabu's avatar
theMackabu committed
   let res = #{
       hello: "world",
       info: #{
theMackabu's avatar
theMackabu committed
         path: request.path,
         url: request.url,
         ver: request.version,
         query: request.query,
theMackabu's avatar
theMackabu committed
       }
   };
   
   json(res)
}

test/loadfile() {
   let file = open_file("test.html");
   html(file.read_string())
}

theMackabu's avatar
theMackabu committed
// remove to test 404 route
theMackabu's avatar
theMackabu committed
* {
theMackabu's avatar
theMackabu committed
   text("this is a wildcard route\ncurrently on: " + path)
theMackabu's avatar
theMackabu committed
}

404 {
   text("404 page")