webcrank-0.2: Webmachine inspired toolkit for building http applications and services.

Safe HaskellNone
LanguageHaskell98

Webcrank.ServerAPI

Synopsis

Documentation

data ServerAPI m Source

A dictionary of functions that Webcrank needs in order to make decisions.

Constructors

ServerAPI 

Fields

srvGetRequestMethod :: m Method

Get the request method of the current request.

srvGetRequestURI :: m ByteString

The full URI of the request.

srvGetRequestHeader :: HeaderName -> m (Maybe ByteString)

Get the request header of the current request.

srvGetRequestTime :: m HTTPDate

Get the time the request was received.

data ReqData Source

Container used to keep track of the decision state and what is known about response while processing a request.

newReqData :: ReqData Source

Smart constructor for creating a ReqData value with initial values.

class HasReqData c where Source

Instances

data ResourceData m Source

A wrapper for the ServerAPI and Resource that should be used to process requests to a path.

class HasResourceData c m | c -> m where Source

Instances

handleRequest Source

Arguments

:: (Applicative m, MonadReader r m, HasResourceData r m, MonadState s m, HasReqData s, MonadCatch m, Functor n) 
=> (forall a. m a -> n (a, ReqData, LogData))

run

-> n (Status, HeadersMap, Maybe Body) 

Process a request according to the webmachine state diagram. Intended for use by server API providers. run is a function which can run process to completion.

WebcrankT is provided as a starting point. For the type

type WaiCrank = ReaderT (Request, HTTPDate) (WebcrankT IO)

an appropriate run function would be

run :: Resource WaiCrank -> Request -> HTTPDate -> WaiCrank a -> IO (a, ReqData, LogData)
run resource req date wa = runReaderT (runWebcrankT wa (ResourceData api resource) newReqData) (req, date)