docs: add curl examples

This commit is contained in:
ato 2023-02-18 23:31:58 +01:00
parent a634528d02
commit a7e7972033
5 changed files with 63 additions and 7 deletions

View File

@ -1,3 +1,13 @@
print([[
===============================================================================
examples:
===============================================================================
curl localhost:3000
=> Hello, World!
===============================================================================
]])
local app = create_app()
app:get("/", function(req, res)

View File

@ -1,3 +1,10 @@
print([[
===============================================================================
Open your browser and go to http://localhost:3000
===============================================================================
]])
local app = create_app()
app:get("/", function(req, res)

View File

@ -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
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)

View File

@ -1,3 +1,13 @@
print([[
===============================================================================
examples:
===============================================================================
curl localhost:3000
===============================================================================
]])
local lib = require("require_lib")
local app = create_app()

View File

@ -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)