Copyright | (c) 2012 Mark Hibberd |
---|---|
License | BSD3 |
Maintainer | Mark Hibberd <mark@hibberd.id.au> |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
Toolkit for building http client libraries over Network.Http.Conduit
Synopsis
- runRequest :: ManagerSettings -> StdMethod -> Text -> RequestTransformer -> Responder b -> IO b
- runRequest' :: ManagerSettings -> Text -> RequestTransformer -> Responder b -> IO b
- runRequestWith :: Manager -> StdMethod -> Text -> RequestTransformer -> Responder b -> IO b
- runRequestWith' :: Manager -> Text -> RequestTransformer -> Responder b -> IO b
- type RequestTransformer = Endo Request
- setApiKey :: ByteString -> RequestTransformer
- setUrlEncodedBody :: [(ByteString, ByteString)] -> RequestTransformer
- setQueryParams :: [(ByteString, Maybe ByteString)] -> RequestTransformer
- setHeaders :: [(CI ByteString, ByteString)] -> RequestTransformer
- setHeader :: (CI ByteString, ByteString) -> RequestTransformer
- addHeader :: (CI ByteString, ByteString) -> RequestTransformer
- stripHeader :: CI ByteString -> RequestTransformer
- setCookieJar :: CookieJar -> UTCTime -> RequestTransformer
- setMethod :: ByteString -> RequestTransformer
- setBody :: ByteString -> RequestTransformer
- setBodyLazy :: ByteString -> RequestTransformer
- setJson :: ToJSON a => a -> RequestTransformer
- type Responder a = Request -> Response ByteString -> a
- data JsonResult a
- = ParseError Text
- | DecodeError Text
- | JsonSuccess a
- parseBody :: FromJSON a => ByteString -> JsonResult a
- parseBodyWith :: FromJSON a => ByteString -> (Text -> b) -> (Text -> b) -> (a -> b) -> b
- basicResponder :: (Int -> ByteString -> a) -> Responder a
- (<>) :: Semigroup a => a -> a -> a
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.
setHeaders :: [(CI ByteString, ByteString)] -> RequestTransformer Source #
Set request headers.
setHeader :: (CI ByteString, ByteString) -> RequestTransformer Source #
Set a request headers.
addHeader :: (CI ByteString, ByteString) -> RequestTransformer Source #
Add a request headers.
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
data JsonResult a Source #
Wrap up json parse and decode errors.
Instances
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.