Copyright | (c) 2014 Bryan O'Sullivan |
---|---|
License | BSD-style |
Maintainer | bos@serpentine.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell98 |
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
withAPISession
.)
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 = Sess.withSession
$ \sess -> Sess.get
sess "http://httpbin.org/get"
We create a Session
using withSession
, 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 withAPISession
.
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 withSessionControl
) is used for all
session requests. The manager settings in the Options
parameter
for the getWith
, postWith
and similar functions is ignored.
- data Session
- newSession :: IO Session
- newAPISession :: IO Session
- withSession :: (Session -> IO a) -> IO a
- withAPISession :: (Session -> IO a) -> IO a
- newSessionControl :: Maybe CookieJar -> ManagerSettings -> IO Session
- withSessionWith :: ManagerSettings -> (Session -> IO a) -> IO a
- withSessionControl :: Maybe CookieJar -> ManagerSettings -> (Session -> IO a) -> IO a
- getSessionCookieJar :: Session -> IO (Maybe CookieJar)
- get :: Session -> String -> IO (Response ByteString)
- post :: Postable a => Session -> String -> a -> IO (Response ByteString)
- head_ :: Session -> String -> IO (Response ())
- options :: Session -> String -> IO (Response ())
- put :: Putable a => Session -> String -> a -> IO (Response ByteString)
- delete :: Session -> String -> IO (Response ByteString)
- customMethod :: String -> Session -> String -> IO (Response ByteString)
- getWith :: Options -> Session -> String -> IO (Response ByteString)
- postWith :: Postable a => Options -> Session -> String -> a -> IO (Response ByteString)
- headWith :: Options -> Session -> String -> IO (Response ())
- optionsWith :: Options -> Session -> String -> IO (Response ())
- putWith :: Putable a => Options -> Session -> String -> a -> IO (Response ByteString)
- deleteWith :: Options -> Session -> String -> IO (Response ByteString)
- customMethodWith :: String -> Options -> Session -> String -> IO (Response ByteString)
- customPayloadMethodWith :: Postable a => String -> Options -> Session -> String -> a -> IO (Response ByteString)
- customHistoriedMethodWith :: String -> Options -> Session -> String -> IO (HistoriedResponse ByteString)
- customHistoriedPayloadMethodWith :: Postable a => String -> Options -> Session -> String -> a -> IO (HistoriedResponse ByteString)
- seshRun :: Lens' Session (Session -> Run Body -> Run Body)
Session creation
A session that spans multiple requests. This is responsible for cookie management and TCP connection reuse.
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
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
:: Maybe CookieJar | If |
-> 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.
:: Maybe CookieJar | If |
-> 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
HTTP verbs
customMethod :: String -> Session -> String -> IO (Response ByteString) Source #
Session
-specific version of customMethod
.
Configurable verbs
optionsWith :: Options -> Session -> String -> IO (Response ()) Source #
Session
-specific version of optionsWith
.
deleteWith :: Options -> Session -> String -> IO (Response ByteString) Source #
Session
-specific version of deleteWith
.
customMethodWith :: String -> Options -> Session -> String -> IO (Response ByteString) Source #
Session
-specific version of customMethodWith
.
customPayloadMethodWith :: Postable a => String -> Options -> Session -> String -> a -> IO (Response ByteString) Source #
Session
-specific version of customPayloadMethodWith
.
customHistoriedMethodWith :: String -> Options -> Session -> String -> IO (HistoriedResponse ByteString) Source #
Session
-specific version of customHistoriedMethodWith
.
Since: 0.5.2.0
customHistoriedPayloadMethodWith :: Postable a => String -> Options -> Session -> String -> a -> IO (HistoriedResponse ByteString) Source #
Session
-specific version of customHistoriedPayloadMethodWith
.
Since: 0.5.2.0