Here's an example showing how to return JSON and how to use parameters sent via a form with POST:
pages = {}
pages["/name"] = function(request)
return '<html><head><title>Form Test</title></head><body>' ..
'<form method="POST" action="/welcome">' ..
'What is your name? <input name="n"/>' ..
'<input type="submit" />' ..
'</form></body></html>'
end
pages["/welcome"] = function(request)
name = request.form["n"]
return "<html><head><title>Welcome</title></head><body><p>Welcome " .. name .. ".</p></body></html>"
end
pages["/json"] = function(request)
return '{ "temperature": 82, "barometer": 30.2 }', 'application/json'
end
w = startWeb({pages = pages})