Not able to run basic usage example
Closed this issue · 1 comments
jwoertink commented
When I run this example, I'm not able to get values back out.
require "kemal"
require "kemal-session"
Kemal::Session.config do |config|
config.secret = "my_super_secret"
end
get "/set" do |env|
number = rand(100)
env.session.int("number", number) # set the value of "number"
"Random number #{number} set."
end
get "/get" do |env|
number = env.session.int?("number") # get the value of "number"
"Value of random number is #{number}."
end
Kemal.run
Then I boot it up and hit the endpoints
$ curl localhost:3000/set
Random number 10 set.
$ curl localhost:3000/get
Value of random number is .
You can see there's no value found when I call get
. Also, if I remove the ?
from the method call, it throws an exception saying the key "number"
isn't there. Maybe I'm missing something?
jwoertink commented
Actually, turns out it works fine in the browser. I forgot I need to use a cookie jar with curl 😅 Looks all good!