File: SimpleSession.hs

package info (click to toggle)
haskell-wreq 0.5.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 380 kB
  • sloc: haskell: 2,992; makefile: 25
file content (24 lines) | stat: -rw-r--r-- 769 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{-# LANGUAGE OverloadedStrings #-}

import Control.Lens
import Network.Wreq
import qualified Network.Wreq.Session as S

main :: IO ()
main = S.withSession $ \sess -> do
  -- Our first request causes the httpbin.org server to set a cookie
  -- in its response.

  S.get sess "http://httpbin.org/cookies/set?name=hi"

  -- The session value manages both cookies and HTTP connection reuse
  -- for us.  When we issue the second request, it should
  -- transparently reuse the same connection, and also send the
  -- cookies that we set during the first request.

  r2 <- S.post sess "http://httpbin.org/post" ["a" := (3 :: Int)]

  -- And here's where we verify that the cookie is still set on the
  -- second request.

  print $ r2 ^. responseCookie "name" . cookieValue