{"title":"Cookies","description":"","section":"cookbook","version":"v1.5","path":"cookbook/cookies","canonical_url":"https://amberframework.org/docs/v1.5/cookbook/cookies","markdown_url":"https://amberframework.org/docs/v1.5/cookbook/cookies.md","inherited":true,"content_markdown":"# Cookies\n\nThis recipe will help you to setup a cookie in your application.\n\n{% hint style=\"warning\" %}\nFirst you need an amber project generated with [Amber CLI](../guides/create-new-app.md) or [from scratch](from-scratch.md).\n{% endhint %}\n\n{% code-tabs %}\n{% code-tabs-item title=\"src/controllers/some\\_controller.cr\" %}\n```crystal\nclass SomeController < ApplicationController\n  def set_cookie\n    cookies[:example] = {\n      value: \"a yummy cookie with amber color\",\n      http_only: true,\n      secure: true\n    }\n    \"Your example cookie has been cooked successfully!\"\n  end\nend\n```\n{% endcode-tabs-item %}\n{% endcode-tabs %}\n\nThen in your routes file:\n\n{% code-tabs %}\n{% code-tabs-item title=\"config/routes.cr\" %}\n```crystal\nAmber::Server.configure do |app|\n  pipeline :web do\n    # pipelines...\n  end\n\n  routes :web do\n    # other routes,,,\n    get \"/set_cookie\", SomeController, :set_cookie\n  end\nend\n```\n{% endcode-tabs-item %}\n{% endcode-tabs %}\n\nAlso see more detailed information about this in[ Cookies Guide](../guides/controllers/cookies.md)."}