-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Composable, type-safe library to build HTTP API servers -- -- WebGear is a library to for building composable, type-safe HTTP API -- servers. WebGear focuses on good documentation and usability. See the -- documentation of WebGear module to get started. @package webgear-server @version 1.3.0 -- | Server implementation of WebGear handlers module WebGear.Server.Handler -- | An arrow implementing a WebGear server. -- -- A good first approximation is to consider ServerHandler to be -- equivalent to the function arrow a -> m b where m -- is a monad. It also supports routing and possibly failing the -- computation when the route does not match. newtype ServerHandler m a b ServerHandler :: (a -> StateT RoutePath (ExceptT RouteMismatch m) b) -> ServerHandler m a b [unServerHandler] :: ServerHandler m a b -> a -> StateT RoutePath (ExceptT RouteMismatch m) b -- | Parts of the request path used by the routing machinery newtype () => RoutePath RoutePath :: [Text] -> RoutePath -- | Run a ServerHandler to produce a result or a route mismatch error. runServerHandler :: Monad m => ServerHandler m a b -> RoutePath -> a -> m (Either RouteMismatch b) -- | Convert a ServerHandler to a WAI application toApplication :: ServerHandler IO (Request `With` '[]) Response -> Application -- | Transform a ServerHandler running in one monad to another -- monad. -- -- This is useful in cases where the server is running in a custom monad -- but you would like to convert it to a WAI application using -- toApplication. -- -- Example usage with a ReaderT monad stack: -- --
-- toApplication (transform f server) -- where -- server :: ServerHandler (ReaderT r IO) (Request `With` '[]) Response -- server = .... -- -- f :: ReaderT r IO a -> IO a -- f action = runReaderT action r --transform :: (forall x. m x -> n x) -> ServerHandler m a b -> ServerHandler n a b instance GHC.Base.Monad m => Control.Arrow.ArrowChoice (WebGear.Server.Handler.ServerHandler m) instance GHC.Base.Monad m => Control.Arrow.ArrowPlus (WebGear.Server.Handler.ServerHandler m) instance GHC.Base.Monad m => Control.Arrow.ArrowZero (WebGear.Server.Handler.ServerHandler m) instance GHC.Base.Monad m => Control.Arrow.Arrow (WebGear.Server.Handler.ServerHandler m) instance GHC.Base.Monad m => Control.Category.Category (WebGear.Server.Handler.ServerHandler m) instance GHC.Base.Monad m => Control.Arrow.Operations.ArrowError WebGear.Core.Handler.RouteMismatch (WebGear.Server.Handler.ServerHandler m) instance GHC.Base.Monad m => WebGear.Core.Handler.Handler (WebGear.Server.Handler.ServerHandler m) m -- | Parsing and rendering of MIME types module WebGear.Server.MIMETypes -- | Instances of this class are used to parse the body of a request as -- specified by a MIME type. class (MIMEType mt) => BodyUnrender m mt a -- | Parse a request body. Return a Left value with error messages -- in case of failure. bodyUnrender :: BodyUnrender m mt a => mt -> Request -> m (Either Text a) -- | Instances of this class serializes a value to a response body as -- specified by a MIME type. class (MIMEType mt) => BodyRender m mt a -- | Render a value in the format specified by the media type. -- -- Returns the response body and the media type to be used in the -- "Content-Type" header. This could be a variant of the original media -- type with additional parameters. bodyRender :: BodyRender m mt a => mt -> Response -> a -> m (MediaType, ResponseBody) -- | A backend that stores all files in memory inMemoryBackend :: BackEnd ByteString -- | A backend that stores files in a temp directory. tempFileBackend :: MonadResource m => m (BackEnd FilePath) instance (GHC.Base.Monad m, Web.Internal.FormUrlEncoded.ToForm a) => WebGear.Server.MIMETypes.BodyRender m WebGear.Core.MIMETypes.FormURLEncoded a instance GHC.Base.Monad m => WebGear.Server.MIMETypes.BodyRender m WebGear.Core.MIMETypes.HTML Data.ByteString.Internal.Type.ByteString instance GHC.Base.Monad m => WebGear.Server.MIMETypes.BodyRender m WebGear.Core.MIMETypes.HTML Data.ByteString.Lazy.Internal.ByteString instance (GHC.Base.Monad m, Data.Aeson.Types.ToJSON.ToJSON a) => WebGear.Server.MIMETypes.BodyRender m WebGear.Core.MIMETypes.JSON a instance GHC.Base.Monad m => WebGear.Server.MIMETypes.BodyRender m WebGear.Core.MIMETypes.OctetStream Data.ByteString.Internal.Type.ByteString instance GHC.Base.Monad m => WebGear.Server.MIMETypes.BodyRender m WebGear.Core.MIMETypes.OctetStream Data.ByteString.Lazy.Internal.ByteString instance (GHC.Base.Monad m, Data.Text.Conversions.ToText a) => WebGear.Server.MIMETypes.BodyRender m WebGear.Core.MIMETypes.PlainText a instance (Control.Monad.IO.Class.MonadIO m, Web.Internal.FormUrlEncoded.FromForm a) => WebGear.Server.MIMETypes.BodyUnrender m WebGear.Core.MIMETypes.FormURLEncoded a instance Control.Monad.IO.Class.MonadIO m => WebGear.Server.MIMETypes.BodyUnrender m WebGear.Core.MIMETypes.HTML Data.ByteString.Internal.Type.ByteString instance Control.Monad.IO.Class.MonadIO m => WebGear.Server.MIMETypes.BodyUnrender m WebGear.Core.MIMETypes.HTML Data.ByteString.Lazy.Internal.ByteString instance (Control.Monad.IO.Class.MonadIO m, Data.Aeson.Types.FromJSON.FromJSON a) => WebGear.Server.MIMETypes.BodyUnrender m WebGear.Core.MIMETypes.JSON a instance Control.Monad.IO.Class.MonadIO m => WebGear.Server.MIMETypes.BodyUnrender m (WebGear.Core.MIMETypes.FormData a) (WebGear.Core.MIMETypes.FormDataResult a) instance Control.Monad.IO.Class.MonadIO m => WebGear.Server.MIMETypes.BodyUnrender m WebGear.Core.MIMETypes.OctetStream Data.ByteString.Internal.Type.ByteString instance Control.Monad.IO.Class.MonadIO m => WebGear.Server.MIMETypes.BodyUnrender m WebGear.Core.MIMETypes.OctetStream Data.ByteString.Lazy.Internal.ByteString instance (Control.Monad.IO.Class.MonadIO m, Data.Text.Conversions.FromText a) => WebGear.Server.MIMETypes.BodyUnrender m WebGear.Core.MIMETypes.PlainText a -- | Server implementation of the BasicAuth' trait. module WebGear.Server.Trait.Auth.Basic instance GHC.Base.Monad m => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Auth.Basic.BasicAuth' 'WebGear.Core.Modifiers.Required scheme m e a) instance GHC.Base.Monad m => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Auth.Basic.BasicAuth' 'WebGear.Core.Modifiers.Optional scheme m e a) -- | Server implementation of the JWTAuth' trait. module WebGear.Server.Trait.Auth.JWT instance (Control.Monad.Time.MonadTime m, WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Auth.Common.AuthorizationHeader scheme)) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Auth.JWT.JWTAuth' 'WebGear.Core.Modifiers.Required scheme m e a) instance (Control.Monad.Time.MonadTime m, WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Auth.Common.AuthorizationHeader scheme)) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Auth.JWT.JWTAuth' 'WebGear.Core.Modifiers.Optional scheme m e a) -- | Server implementation of the Body trait. module WebGear.Server.Trait.Body instance (GHC.Base.Monad m, WebGear.Server.MIMETypes.BodyUnrender m mt val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Body.Body mt val) instance (GHC.Base.Monad m, WebGear.Server.MIMETypes.BodyRender m mt val) => WebGear.Core.Trait.Set (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Body.Body mt val) instance GHC.Base.Monad m => WebGear.Core.Trait.Set (WebGear.Server.Handler.ServerHandler m) WebGear.Core.Trait.Body.UnknownContentBody -- | Server implementation of the Cookie and SetCookie -- traits. module WebGear.Server.Trait.Cookie instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Cookie.Cookie 'WebGear.Core.Modifiers.Required name val) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Cookie.Cookie 'WebGear.Core.Modifiers.Optional name val) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name) => WebGear.Core.Trait.Set (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Cookie.SetCookie 'WebGear.Core.Modifiers.Required name) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name) => WebGear.Core.Trait.Set (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Cookie.SetCookie 'WebGear.Core.Modifiers.Optional name) -- | Server implementation of the RequestHeader and -- ResponseHeader traits. module WebGear.Server.Trait.Header instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Header.RequestHeader 'WebGear.Core.Modifiers.Required 'WebGear.Core.Modifiers.Strict name val) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Header.RequestHeader 'WebGear.Core.Modifiers.Optional 'WebGear.Core.Modifiers.Strict name val) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Header.RequestHeader 'WebGear.Core.Modifiers.Required 'WebGear.Core.Modifiers.Lenient name val) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Header.RequestHeader 'WebGear.Core.Modifiers.Optional 'WebGear.Core.Modifiers.Lenient name val) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.ToHttpApiData val) => WebGear.Core.Trait.Set (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Header.ResponseHeader 'WebGear.Core.Modifiers.Required name val) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.ToHttpApiData val) => WebGear.Core.Trait.Set (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Header.ResponseHeader 'WebGear.Core.Modifiers.Optional name val) -- | Server implementation of the Method trait. module WebGear.Server.Trait.Method instance GHC.Base.Monad m => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) WebGear.Core.Trait.Method.Method -- | Server implementation of the path traits. module WebGear.Server.Trait.Path instance GHC.Base.Monad m => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) WebGear.Core.Trait.Path.Path instance (GHC.Base.Monad m, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.Path.PathVar tag val) instance GHC.Base.Monad m => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) WebGear.Core.Trait.Path.PathEnd -- | Server implementation of the QueryParam trait. module WebGear.Server.Trait.QueryParam instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.QueryParam.QueryParam 'WebGear.Core.Modifiers.Required 'WebGear.Core.Modifiers.Strict name val) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.QueryParam.QueryParam 'WebGear.Core.Modifiers.Optional 'WebGear.Core.Modifiers.Strict name val) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.QueryParam.QueryParam 'WebGear.Core.Modifiers.Required 'WebGear.Core.Modifiers.Lenient name val) instance (GHC.Base.Monad m, GHC.TypeLits.KnownSymbol name, Web.Internal.HttpApiData.FromHttpApiData val) => WebGear.Core.Trait.Get (WebGear.Server.Handler.ServerHandler m) (WebGear.Core.Trait.QueryParam.QueryParam 'WebGear.Core.Modifiers.Optional 'WebGear.Core.Modifiers.Lenient name val) -- | Server implementation of the Status trait. module WebGear.Server.Trait.Status instance GHC.Base.Monad m => WebGear.Core.Trait.Set (WebGear.Server.Handler.ServerHandler m) WebGear.Core.Trait.Status.Status -- | Server implementation of all traits supported by WebGear. -- -- This modules only exports orphan instances imported from other -- modules. Hence the haddock documentation will be empty. module WebGear.Server.Traits -- | Main module for WebGear server. -- -- Import this module to get all required types and functions to build a -- WebGear server. Alternatively, import individual modules under -- WebGear.Server. -- -- Typical usage to implement a server is: -- --
-- import WebGear.Server -- import Network.Wai (Application) -- import qualified Network.Wai.Handler.Warp as Warp -- -- -- | A monad stack for you application -- type App a = .... -- -- -- | Convert the App monad to IO -- runApp :: App a -> IO a -- runApp = .... -- -- -- | Handler for the server -- myHandler :: Handler h App => RequestHandler h '[] -- myHandler = .... -- -- app :: Application -- app = toApplication (transform runApp myHandler) -- -- main :: IO () -- main = Warp.run port app --module WebGear.Server