craze- HTTP Racing Library

Safe HaskellSafe




type RacerHandler headerTy bodyTy a = CurlResponse_ headerTy bodyTy -> IO a Source

A RacerHandler is simply a function for transforming a response after it is received. The handler is only applied to successful requests before they are checked by the RacerChecker.

This is primarily for extracting or parsing a CurlResponse_ before doing any further work. The type returned by the handler will be used as the input of the checker and will be the return type of functions like raceGet.

type RacerChecker a = a -> Bool Source

A function that computes whether or not a result is valid or not.

A racer will discard successful responses it get from its clients if they do not pass the checker.

This step allows the racer to potentially discard responses that, while technically successful, do not contain the expected result (e.g. APIs that return errors as HTTP 200s, rate limitting messages, or unexpected formats).

type RacerProvider = IO ProviderOptions Source

A provider is simply a factory function for ProviderOptions, which are used to configure a client.

data ProviderOptions Source

Configuration used to set up an individual client in the race.




poOptions :: [CurlOption]

Options to pass down to Curl.

poDelay :: Maybe Int

Number of microseconds to delay the request by.

Delays can be used to give other clients a headstart. This is useful in cases were some clients are more costly to use than others (e.g. Bandwidth costs, resource usage, etc).

poTag :: Text

A tag to identify this type provider.

Tags are not required to be unique, but they are generally more helpful if they are.

data ClientStatus a Source

The status of running a single client.


Successful a

A successful response (passed the checker). A race will usually only have one successful response.

Failed a

A response that was received but failed to pass the checker.

Errored SomeException

An exception thrown while using the client.


The operation is still pending, was cancelled, or was never started.


data RacerResult a Source

The result of a racing operation. This can be used to collect statistics on which providers win more often, etc.

data Racer headerTy bodyTy a Source

A record describing the rules for racing requests.




racerHandler :: RacerHandler headerTy bodyTy a
racerChecker :: RacerChecker a
racerProviders :: [RacerProvider]

On a Racer, each RaceProvider represents a separate client configuration. When performing a race, each provider will be used to spwan a client and perform a request. This allows one to control the number of requests performed and with which CurlOptions.

racerDebug :: Bool

When set to True, debugging messages will be written to stdout.

racerReturnLast :: Bool

When set to True, the Racer will attempt to return the last response in the event that all responses failed to pass the checker. This can be used for identifying error conditions.