wrecker-0.1.1.1: A HTTP Performance Benchmarker

Safe HaskellNone
LanguageHaskell2010

Wrecker.Recorder

Synopsis

Documentation

data Event Source #

Constructors

Event 

Fields

Instances

data Recorder Source #

An opaque type for recording actions for profiling. No means are provided for creating a Recorder directly. To obtain a Recorder use either run or defaultMain.

Constructors

Recorder 

Fields

record :: forall a. Recorder -> String -> IO a -> IO a Source #

record is how HTTP actions are profiled. Wrap each action of interest in a call to record.

import Network.Wreq.Session
import Data.Aeson

loginReshare :: Recorder -> IO ()
loginReshare recorder = withSession $ \session -> do
  let rc = record recorder

  Object user <- rc "login"
               $ asJSON
            =<< ( post session "https://somesite.com/login"
                $ object [ "email"    .= "example@example.com"
                         , "password" .= "12345678"
                        ]
                )
  let Just feedUrl = H.lookup "feed" user
  itemRef : _ <- rc "get feed"
               $ asJSON
             =<< ( post session feedUrl
                 $ object [ "email"    .= "example@example.com"
                          , "password" .= "12345678"
                          ]
                 )
  rc "reshare" $ post session "https://somesite.com/share"
               $ object [ "type" : "reshare"
                        , "ref"  : itemRef
                        ]

In this case the loginReshare script would record three actions: "login", "get feed" and "reshare".

record measures the elapsed time of the call, and catches HttpException in the case of failure. This means failures must be thrown if they are to be properly recorded.