network-api-support-0.3.4: Toolkit for building http client libraries over Network.Http.Conduit

Copyright(c) 2012 Mark Hibberd
LicenseBSD3
MaintainerMark Hibberd <mark@hibberd.id.au>
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Network.Api.Support

Contents

Description

Toolkit for building http client libraries over Network.Http.Conduit

Synopsis

Request runners

runRequest :: ManagerSettings -> StdMethod -> Text -> RequestTransformer -> Responder b -> IO b Source #

Run a request using the specified settings, method, url and request transformer.

runRequest' :: ManagerSettings -> Text -> RequestTransformer -> Responder b -> IO b Source #

Run a request using the specified settings, url and request transformer. The method | can be set using the setMethod transformer. This is only useful if you require a | custom http method. Prefer runRequest where possible.

runRequestWith :: Manager -> StdMethod -> Text -> RequestTransformer -> Responder b -> IO b Source #

Run a request using the specified settings, method, url and request transformer.

Prefer this to runRequest as recreating the manager every time is very inefficient.

runRequestWith' :: Manager -> Text -> RequestTransformer -> Responder b -> IO b Source #

Run a request using the specified manager, url and request transformer. The method can be set using the setMethod transformer. This is only useful if you require a custom http method. Prefer runRequest where possible.

Prefer this to runRequest' as recreating the manager every time is very inefficient.

Request transformers

type RequestTransformer = Endo Request Source #

A RequestTransformer allows you to build up attributes on the request. | RequestTransformer is simply an Endo, and therefore has a Monoid, so | can be combined with <>.

setApiKey :: ByteString -> RequestTransformer Source #

Set an api key for use with basic auth.

setUrlEncodedBody :: [(ByteString, ByteString)] -> RequestTransformer Source #

Set URL encoded form params on the request body.

setQueryParams :: [(ByteString, Maybe ByteString)] -> RequestTransformer Source #

Set request query parameters.

stripHeader :: CI ByteString -> RequestTransformer Source #

Set a request headers.

setCookieJar :: CookieJar -> UTCTime -> RequestTransformer Source #

Register all cookies in cookie jar against request.

setMethod :: ByteString -> RequestTransformer Source #

Set the request method to be the specified name.

setBody :: ByteString -> RequestTransformer Source #

Set the request body from the specified byte string.

setBodyLazy :: ByteString -> RequestTransformer Source #

Set the request body from the specified lazy byte string.

setJson :: ToJSON a => a -> RequestTransformer Source #

Set the request body from the value which can be converted to JSON.

Responders

type Responder a = Request -> Response ByteString -> a Source #

Response handler.

data JsonResult a Source #

Wrap up json parse and decode errors.

Instances
Monad JsonResult Source # 
Instance details

Defined in Network.Api.Support.Response

Methods

(>>=) :: JsonResult a -> (a -> JsonResult b) -> JsonResult b #

(>>) :: JsonResult a -> JsonResult b -> JsonResult b #

return :: a -> JsonResult a #

fail :: String -> JsonResult a #

Functor JsonResult Source # 
Instance details

Defined in Network.Api.Support.Response

Methods

fmap :: (a -> b) -> JsonResult a -> JsonResult b #

(<$) :: a -> JsonResult b -> JsonResult a #

Applicative JsonResult Source # 
Instance details

Defined in Network.Api.Support.Response

Methods

pure :: a -> JsonResult a #

(<*>) :: JsonResult (a -> b) -> JsonResult a -> JsonResult b #

liftA2 :: (a -> b -> c) -> JsonResult a -> JsonResult b -> JsonResult c #

(*>) :: JsonResult a -> JsonResult b -> JsonResult b #

(<*) :: JsonResult a -> JsonResult b -> JsonResult a #

Eq a => Eq (JsonResult a) Source # 
Instance details

Defined in Network.Api.Support.Response

Methods

(==) :: JsonResult a -> JsonResult a -> Bool #

(/=) :: JsonResult a -> JsonResult a -> Bool #

Show a => Show (JsonResult a) Source # 
Instance details

Defined in Network.Api.Support.Response

parseBody :: FromJSON a => ByteString -> JsonResult a Source #

Parse and decode body.

parseBodyWith :: FromJSON a => ByteString -> (Text -> b) -> (Text -> b) -> (a -> b) -> b Source #

Parse and decode body handling error cases and success case.

basicResponder :: (Int -> ByteString -> a) -> Responder a Source #

Lift function handling status code and body into a responder.

Compatibility

(<>) :: Semigroup a => a -> a -> a infixr 6 #

An associative operation.