Documentation

Cookies

Browse documentation

Read this page as HTML, Markdown, or structured JSON—or open the published Markdown with an AI assistant. Gemini receives the prompt through your clipboard because its signed-out page does not reliably prefill URL text; paste when the new tab opens. External assistants need the public site URL.

Cookies

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
Crystal
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
Crystal
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.