Cookies

Last updated 6 months ago

This recipe will help you to setup a cookie in your application.

First you need an amber project generated with Amber CLI or from scratch.

src/controllers/some_controller.cr
class SomeController < ApplicationController
def set_cookie
cookies[:example] = {
value: "a yummy cookie with amber color",
http_only: true,
secure: true
}
"Your example cookie has been cooked successfully!"
end
end

Then in your routes file:

config/routes.cr
Amber::Server.configure do |app|
pipeline :web do
# pipelines...
end
‚Äč
routes :web do
# other routes,,,
get "/set_cookie", SomeController, :set_cookie
end
end

Also see more detailed information about this in Cookies Guide.