README.org

#+STARTUP: showall
#+OPTIONS: ^:{}
* elli_cookie
[[https://travis-ci.org/elli-lib/elli_cookie][file:https://travis-ci.org/elli-lib/elli_cookie.svg?branch=master]]
[[https://hex.pm/packages/elli_cookie][file:https://img.shields.io/hexpm/v/elli_cookie.svg]]

A library application for reading, setting,
and otherwise managing cookies in [[https://github.com/knutin/elli][Elli]].

** Usage
See the large test set in [[file:test/elli_cookie_test.erl][elli_cookie_test]] for more thorough usage examples.

*** Basic Cookie Management and Cookie Option Settings
In an Elli callback module:
#+BEGIN_SRC erlang
  handle(Req, _Config) ->
    Cookies = elli_cookie:parse(Req),

    %% retrieve a cookie value ...
    _PublicKey = elli_cookie:get(<<"key">>, Cookies),
    %% ... and do something with it

    %% create new cookie for domain www.example.com that expires in two weeks
    FizzCookie = elli_cookie:new(<<"fizz">>, <<"buzz">>,
                                 [elli_cookie:domain(<<"www.example.com">>),
                                  elli_cookie:expires({2, weeks})]),

    %% delete key cookie
    DeleteKeyCookie = elli_cookie:delete(<<"key">>),

    %% return response with cookies
    {ok, [DeleteKeyCookie, FizzCookie], <<"key deleted; fizz set">>}.
#+END_SRC