api-maker-0.1.0.6: Package to make APIs
Safe HaskellNone
LanguageHaskell2010

Network.HTTP.ApiMaker.Class

Synopsis

Documentation

class (HttpMethod (Method r), HttpBody (Body r), HttpResponse (Response r), HttpBodyAllowed (AllowsBody (Method r)) (ProvidesBody (Body r))) => Request cfg r where Source #

Class definition for a Request. Every request should implement this, the rest is then handled by the library. See mkReq to create a request, the functions mkReqM and runRequests to build a SafeReqM monad that shares the same state, session and configuration, and finally runReqM, runSessReqM, runReqWithParamsM and runSessReqWithParamsM to run the monad.

Minimal complete definition

method, url, body, response, option, process

Associated Types

type Method r :: Type Source #

type Body r :: Type Source #

type Response r :: Type Source #

type Output r :: Type Source #

Methods

method :: cfg -> r -> Method r Source #

url :: cfg -> r -> Url 'Https Source #

body :: cfg -> r -> Body r Source #

response :: cfg -> r -> Proxy (Response r) Source #

option :: cfg -> r -> IO (Option 'Https) Source #

requestModifier :: cfg -> r -> Request -> IO Request Source #

process :: (MonadHttp m, MonadError SafeException m, SessionState st) => cfg -> r -> Response r -> StateT st m (Output r) Source #

data Config cfg Source #

Configuration that is passed from request to request to hold the session and default https header options. It also holds a user defined configuration.

Constructors

Config 

class SessionState st where Source #

Session state contract.

Instances

Instances details
SessionState Session Source #

Simple session state implemention.

Instance details

Defined in Network.HTTP.ApiMaker.SessionState

data Session Source #

Simple session state. This probably is sufficient for the day-to-day use.

emptySession :: Session Source #

Empty session state.

runSafeReqM Source #

Arguments

:: MonadIO m 
=> Config cfg

Config including HttpConfig to use

-> SafeReqM cfg a

Computation to run

-> m (Either SafeException a) 

Safely run the request monad.

type SafeReqSt sessionState cfg a = StateT sessionState (SafeReqM cfg) a Source #

Safe request monad with customized session state sessionState, Config cfg and result a.

type SafeReq cfg a = SafeReqSt Session cfg a Source #

Safe request monad with predetermined Session, config cfg and result a.

newtype SafeReqM cfg a Source #

Safe request, e.g. all errors are caught and tured into exceptions.

Constructors

SafeReqM (ExceptT SafeException (ReaderT (Config cfg) IO) a) 

Instances

Instances details
MonadError SafeException (SafeReqM cfg) Source # 
Instance details

Defined in Network.HTTP.ApiMaker.Class

Methods

throwError :: SafeException -> SafeReqM cfg a #

catchError :: SafeReqM cfg a -> (SafeException -> SafeReqM cfg a) -> SafeReqM cfg a #

MonadBase IO (SafeReqM cfg) Source # 
Instance details

Defined in Network.HTTP.ApiMaker.Class

Methods

liftBase :: IO α -> SafeReqM cfg α #

Monad (SafeReqM cfg) Source # 
Instance details

Defined in Network.HTTP.ApiMaker.Class

Methods

(>>=) :: SafeReqM cfg a -> (a -> SafeReqM cfg b) -> SafeReqM cfg b #

(>>) :: SafeReqM cfg a -> SafeReqM cfg b -> SafeReqM cfg b #

return :: a -> SafeReqM cfg a #

Functor (SafeReqM cfg) Source # 
Instance details

Defined in Network.HTTP.ApiMaker.Class

Methods

fmap :: (a -> b) -> SafeReqM cfg a -> SafeReqM cfg b #

(<$) :: a -> SafeReqM cfg b -> SafeReqM cfg a #

Applicative (SafeReqM cfg) Source # 
Instance details

Defined in Network.HTTP.ApiMaker.Class

Methods

pure :: a -> SafeReqM cfg a #

(<*>) :: SafeReqM cfg (a -> b) -> SafeReqM cfg a -> SafeReqM cfg b #

liftA2 :: (a -> b -> c) -> SafeReqM cfg a -> SafeReqM cfg b -> SafeReqM cfg c #

(*>) :: SafeReqM cfg a -> SafeReqM cfg b -> SafeReqM cfg b #

(<*) :: SafeReqM cfg a -> SafeReqM cfg b -> SafeReqM cfg a #

MonadIO (SafeReqM cfg) Source # 
Instance details

Defined in Network.HTTP.ApiMaker.Class

Methods

liftIO :: IO a -> SafeReqM cfg a #

MonadHttp (SafeReqM cfg) Source # 
Instance details

Defined in Network.HTTP.ApiMaker.Class

throwUserException :: (MonadError SafeException m, Exception e) => e -> m a Source #

Throw an Exception to the SafeReqM Monad.