Skip to content

Instantly share code, notes, and snippets.

@leite
Created January 11, 2014 18:06
Show Gist options
  • Save leite/8374450 to your computer and use it in GitHub Desktop.
Save leite/8374450 to your computer and use it in GitHub Desktop.
dead simple sinatra openresty application
local sinatra = require('sinatra');
local app = sinatra.app:new()
app:get("/", function()
return "Hello, World "
end)
app:get("/:name", function()
return "Hello, " .. params.name;
end)
app:get("/age/:age", function(age)
return "You are " .. tostring(age) .. " years old."
end)
app:post("/", function()
return "name: " .. (params.name or 'not sent')
end)
app:run()
@leite
Copy link
Author

leite commented Jan 11, 2014

run this with openresty ...

teste with http://domain.name, http://domain.name/xsayarsa, http://domain.name/age/23 ou com POST request

curl --data "name=xsayarsa&param2=value2" http://domain.name

@ademar111190
Copy link

but it is not a post :/

I'm thinking something like:

curl -X POST -H "Content-Type: application/json" --data '{"username":"ademar","password":"senha123"}' http://127.0.0.1/signin

@leite
Copy link
Author

leite commented Jan 11, 2014

I think it's a HTTP POST :)

you are trying to send raw data structures (json) to a webservice, I dont recomend in that case (a login, register ...)

see, it should have a variable to assign that structure as follows:

curl --data 'json={"username":"ademar","password":"senha123"}' http://localhost/signin

what i do recommend is that:

curl --data "username=ademar&password=senha123" http://localhost/signin

@ademar111190
Copy link

works :)

but don't need the '-X POST' ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment