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
?
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
?
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