wreq-0.5.3.3: An easy-to-use HTTP client library.
Copyright(c) 2014 Bryan O'Sullivan
LicenseBSD-style
Maintainerbos@serpentine.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell98

Network.Wreq.Session

Description

The functions in this module use a Session to handle the following common needs:

  • TCP connection reuse. This is important for performance when multiple requests go to a single server, particularly if TLS is being used.
  • Transparent cookie management. Any cookies set by the server persist from one request to the next. (Bypass this overhead using newAPISession.)

This module is designed to be used alongside the Network.Wreq module. Typical usage will look like this:

import Network.Wreq
import qualified Network.Wreq.Session as Sess

main = do
  sess <- Sess.newSession
  Sess.get sess "http://httpbin.org/get"

We create a Session using newSession, then pass the session to subsequent functions. When talking to a REST-like service that does not use cookies, it is more efficient to use newAPISession.

Note the use of qualified import statements in the examples above, so that we can refer unambiguously to the Session-specific implementation of HTTP GET.

One Manager (possibly set with newSessionControl) is used for all session requests. The manager settings in the Options parameter for the getWith, postWith and similar functions is ignored.

Synopsis

Session creation

data Session Source #

A session that spans multiple requests. This is responsible for cookie management and TCP connection reuse.

Instances

Instances details
Show Session Source # 
Instance details

Defined in Network.Wreq.Internal.Types

newSession :: IO Session Source #

Create a Session.

This session manages cookies and uses default session manager configuration.

Since: 0.5.2.0

newAPISession :: IO Session Source #

Create a session.

This uses the default session manager settings, but does not manage cookies. It is intended for use with REST-like HTTP-based APIs, which typically do not use cookies.

Since: 0.5.2.0

withSession :: (Session -> IO a) -> IO a Source #

Deprecated: Use newSession instead.

Create a Session, passing it to the given function. The Session will no longer be valid after that function returns.

This session manages cookies and uses default session manager configuration.

withAPISession :: (Session -> IO a) -> IO a Source #

Deprecated: Use newAPISession instead.

Create a session.

This uses the default session manager settings, but does not manage cookies. It is intended for use with REST-like HTTP-based APIs, which typically do not use cookies.

More control-oriented session creation

newSessionControl Source #

Arguments

:: Maybe CookieJar

If Nothing is specified, no cookie management will be performed.

-> ManagerSettings 
-> IO Session 

Create a session, using the given cookie jar and manager settings.

Since: 0.5.2.0

withSessionWith :: ManagerSettings -> (Session -> IO a) -> IO a Source #

Deprecated: Use newSessionControl instead.

Create a session, using the given manager settings. This session manages cookies.

withSessionControl Source #

Arguments

:: Maybe CookieJar

If Nothing is specified, no cookie management will be performed.

-> ManagerSettings 
-> (Session -> IO a) 
-> IO a 

Deprecated: Use newSessionControl instead.

Create a session, using the given cookie jar and manager settings.

Get information about session state

getSessionCookieJar :: Session -> IO (Maybe CookieJar) Source #

Extract current CookieJar from a Session

Since: 0.5.2.0

HTTP verbs

get :: Session -> String -> IO (Response ByteString) Source #

Session-specific version of get.

post :: Postable a => Session -> String -> a -> IO (Response ByteString) Source #

Session-specific version of post.

head_ :: Session -> String -> IO (Response ()) Source #

Session-specific version of head_.

options :: Session -> String -> IO (Response ()) Source #

Session-specific version of options.

put :: Putable a => Session -> String -> a -> IO (Response ByteString) Source #

Session-specific version of put.

delete :: Session -> String -> IO (Response ByteString) Source #

Session-specific version of delete.

Configurable verbs

postWith :: Postable a => Options -> Session -> String -> a -> IO (Response ByteString) Source #

Session-specific version of postWith.

headWith :: Options -> Session -> String -> IO (Response ()) Source #

Session-specific version of headWith.

optionsWith :: Options -> Session -> String -> IO (Response ()) Source #

Session-specific version of optionsWith.

putWith :: Putable a => Options -> Session -> String -> a -> IO (Response ByteString) Source #

Session-specific version of putWith.

Extending a session

seshRun :: Lens' Session (Session -> Run Body -> Run Body) Source #