diff --git a/examples/hello.lua b/examples/hello.lua index a3a1887..537f383 100644 --- a/examples/hello.lua +++ b/examples/hello.lua @@ -1,3 +1,13 @@ +print([[ + +=============================================================================== +examples: +=============================================================================== +curl localhost:3000 +=> Hello, World! +=============================================================================== +]]) + local app = create_app() app:get("/", function(req, res) diff --git a/examples/html.lua b/examples/html.lua index 25e52af..db02999 100644 --- a/examples/html.lua +++ b/examples/html.lua @@ -1,3 +1,10 @@ +print([[ + +=============================================================================== +Open your browser and go to http://localhost:3000 +=============================================================================== +]]) + local app = create_app() app:get("/", function(req, res) diff --git a/examples/multipart.lua b/examples/multipart.lua index 4c05120..e9584ac 100644 --- a/examples/multipart.lua +++ b/examples/multipart.lua @@ -1,12 +1,21 @@ +print([[ + +=============================================================================== +examples: +=============================================================================== +curl -F "test=@README.md" localhost:3000/submit +=============================================================================== +]]) + local app = create_app() -app:post("/", function(req,res) - if req.parts.myfile == nil then +app:post("/", function(req, res) + if req.parts.test == nil then res.status = 400 res.body = "Missing myfile field" return res end - fs:write("yololo.txt", req.parts.myfile.content) + fs:write("yololo.txt", req.parts.test.content) return res end) diff --git a/examples/require.lua b/examples/require.lua index aa99dcf..5b17359 100644 --- a/examples/require.lua +++ b/examples/require.lua @@ -1,8 +1,18 @@ +print([[ + +=============================================================================== +examples: +=============================================================================== +curl localhost:3000 +=============================================================================== +]]) + + local lib = require("require_lib") local app = create_app() -app:get("/", function(req,res) +app:get("/", function(req, res) return lib.identity(res) end) diff --git a/examples/server.lua b/examples/server.lua index fc80af2..0df6dfb 100644 --- a/examples/server.lua +++ b/examples/server.lua @@ -1,3 +1,25 @@ +print([[ + +=============================================================================== +examples: +=============================================================================== +curl localhost:3000 +=> Not Found + +curl localhost:3000/42 +=> {"data":"42"} + +curl -d "test=hello&test2=world" localhost:3000/submit +=> hello world + +curl localhost:3000/admin +=> Admin + +curl localhost:3001 +=> Admin +=============================================================================== +]]) + --[[ Admin Section ]] @@ -20,9 +42,7 @@ app:get("/:segment", function(req, res) end) app:post("/submit", function(req, res) - for k,v in pairs(req.form) do - print(k,v) - end + res.body = req.form.test .. " " .. req.form.test2 return res end)