4

Can anyone please provide me with a minimal example of cookies with servant-server, wai, warp, etc.?

For example, a cookie with a single field "language" with value "en"

Is there an easy way like happstack-lite addCookies and lookCookieValue?

RamiroPastor
  • 1,085
  • 1
  • 7
  • 18

1 Answers1

5

To write cookies:

Get '[JSON] (Headers '[Header "Set-Cookie" SetCookie] ...)

SetCookie has ToHttpApiData instance in recent http-api-data, so this just works.

And to read cookies I make own newtype, as Cookies is a type alias in cookie so we cannot write instance for it directly.

newtype Cookies' = Cookies' Cookies -- type Cookies = [(BS.ByteString, BS.ByteString)]

instance FromHttpApiData Cookies' where
  parseHeader = return . Cookies' . parseCookies
  parseQueryParam = return . Cookies' . parseCookies . TE.encodeUtf8
phadej
  • 11,947
  • 41
  • 78