-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A web framework that integrates Servant, ClassyPrelude, EKG, fast-logger, wai-cli… -- -- Inspired by Dropwizard, Magicbane provides a packaged framework for -- developing web services using the best available libraries, including -- Servant, ClassyPrelude, Aeson, EKGmonad-metrics, -- fast-loggermonad-logger, wai-cli and others. @package magicbane @version 0.1.3 -- | Integrates the refinement types from the refined library with aeson. module Magicbane.Validation instance Data.Aeson.Types.ToJSON.ToJSON α => Data.Aeson.Types.ToJSON.ToJSON (Refined.Refined ρ α) instance (Data.Aeson.Types.FromJSON.FromJSON α, Refined.Predicate ρ α) => Data.Aeson.Types.FromJSON.FromJSON (Refined.Refined ρ α) -- | Various useful functions. module Magicbane.Util -- | Merges two JSON objects recursively. When the values are not objects, -- just returns the left one. mergeVal :: Value -> Value -> Value -- | Encodes key-value data as application/x-www-form-urlencoded. writeForm :: (ConvertibleStrings α Text, ConvertibleStrings β Text, ConvertibleStrings LByteString γ) => [(α, β)] -> γ -- | Decodes key-value data from application/x-www-form-urlencoded. readForm :: (ConvertibleStrings Text α, ConvertibleStrings Text β, ConvertibleStrings γ LByteString) => γ -> Maybe [(α, β)] -- | Reads a Servant incoming form as a list of key-value pairs (for use in -- FromForm instances). formList :: Form -> [(Text, Text)] -- | Converts a flat key-value form with keys in typical nesting syntax -- (e.g. "one[two][three]") to an Aeson Value with nesting (for use in -- FromForm instances). formToObject :: [(Text, Text)] -> Value formKey :: Parser [Text] -- | Parses any string into a URI. parseUri :: ConvertibleStrings α String => α -> URI -- | Prepares text for inclusion in a URL. -- --
--   >>> :set -XOverloadedStrings
--   
--   >>> slugify "Hello & World!"
--   "hello-and-world"
--   
slugify :: Text -> Text -- | Creates a simple text/plain ServantErr. errText :: ServantErr -> LByteString -> ServantErr -- | Creates and throws a simple text/plain ServantErr. throwErrText :: MonadError ServantErr μ => ServantErr -> LByteString -> μ α -- | Provides metrics via monad-metrics/EKG in a Magicbane app context. -- Also reexports Wai metrics middleware. module Magicbane.Metrics newtype ModMetrics ModMetrics :: Metrics -> ModMetrics forkMetricsServer :: ByteString -> Int -> IO Server -- | Creates a metrics module with a particular Store. The Store should -- come from the backend you want to use for storing the metrics. For -- development, a simple backend that shows metrics on a web page is -- ekg-wai, reexported here. newMetricsWith :: Store -> IO ModMetrics instance (Data.Has.Has Magicbane.Metrics.ModMetrics α, GHC.Base.Monad μ, Control.Monad.Reader.Class.MonadReader α μ) => Control.Monad.Metrics.MonadMetrics μ -- | Provides logging via monad-logger/fast-logger in a Magicbane app -- context. module Magicbane.Logging newtype ModLogger ModLogger :: (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) -> ModLogger -- | Creates a logger module. Also returns the logger itself for using -- outside of your Magicbane app (e.g. in some WAI middleware). newLogger :: LogType -> IO (TimedFastLogger, ModLogger) instance (Data.Has.Has Magicbane.Logging.ModLogger α, GHC.Base.Monad μ, Control.Monad.IO.Class.MonadIO μ, Control.Monad.Reader.Class.MonadReader α μ) => Control.Monad.Logger.MonadLogger μ instance (Data.Has.Has Magicbane.Logging.ModLogger α, Control.Monad.IO.Class.MonadIO μ, Control.Monad.Reader.Class.MonadReader α μ) => Control.Monad.Logger.MonadLoggerIO μ -- | Provides an HTTP(S) client via http-client(-tls) in a Magicbane app -- context. Also provides a simple composable interface for making -- arbitrary requests, based on http-client-conduit. That lets you plug -- stream parsers (e.g. html-conduit: 'performWithFn ($$ sinkDoc)') -- directly into the reading of the response body. module Magicbane.HTTPClient newtype ModHttpClient ModHttpClient :: Manager -> ModHttpClient newHttpClient :: IO ModHttpClient type MonadHTTP ψ μ = (HasHttpManager ψ, MonadReader ψ μ, MonadIO μ, MonadBaseControl IO μ) runHTTP :: EitherT ε μ α -> μ (Either ε α) -- | Creates a request from a URI. reqU :: (MonadHTTP ψ μ) => URI -> EitherT Text μ Request -- | Creates a request from a string of any type, parsing it into a URI. reqS :: (MonadHTTP ψ μ, ConvertibleStrings σ String) => σ -> EitherT Text μ Request -- | Configures the request to not throw errors on error status codes. anyStatus :: (MonadHTTP ψ μ) => Request -> EitherT Text μ Request -- | Sets a x-www-form-urlencoded form as the request body (also sets the -- content-type). postForm :: (MonadHTTP ψ μ) => [(Text, Text)] -> Request -> EitherT Text μ Request -- | Performs the request, using a given function to read the body. This is -- what all other performWith functions are based on. performWithFn :: (MonadHTTP ψ μ, MonadCatch μ) => (ConduitM ι ByteString μ () -> μ ρ) -> Request -> EitherT Text μ (Response ρ) -- | Performs the request, ignoring the body. performWithVoid :: (MonadHTTP ψ μ, MonadCatch μ) => Request -> EitherT Text μ (Response ()) -- | Performs the request, reading the body into a lazy ByteString. performWithBytes :: (MonadHTTP ψ μ, MonadCatch μ) => Request -> EitherT Text μ (Response LByteString) instance Data.Has.Has Magicbane.HTTPClient.ModHttpClient α => Network.HTTP.Client.Types.HasHttpManager α -- | Extends Servant with context. Basically wrapping Servant in a ReaderT -- of your type. Which should be a tuple of all your moudles and configs -- and stuff, so that the Data.Has module would let you access these -- items by type. module Magicbane.App newtype MagicbaneApp β α MagicbaneApp :: ReaderT β Handler α -> MagicbaneApp β α [unMagicbaneApp] :: MagicbaneApp β α -> ReaderT β Handler α runMagicbaneHandler :: β -> MagicbaneApp β α -> Handler α -- | Constructs a WAI application from an API definition, a Servant context -- (used for auth mainly), the app context and the actual action -- handlers. magicbaneApp :: (HasServer * api ([] *), HasServer * api context) => Proxy * api -> Context context -> t -> ServerT * api (MagicbaneApp t) -> Application -- | Gets a value of any type from the context. askObj :: (Has β α, MonadReader α μ) => μ β -- | Gets a thing from a value of any type from the context. (Useful for -- configuration fields.) askOpt :: (Has β α, MonadReader α μ) => (β -> ψ) -> μ ψ instance Control.Monad.Reader.Class.MonadReader β (Magicbane.App.MagicbaneApp β) instance Control.Monad.Error.Class.MonadError Servant.Server.Internal.ServantErr.ServantErr (Magicbane.App.MagicbaneApp β) instance Control.Monad.Catch.MonadCatch (Magicbane.App.MagicbaneApp β) instance Control.Monad.Catch.MonadThrow (Magicbane.App.MagicbaneApp β) instance Control.Monad.Base.MonadBase GHC.Types.IO (Magicbane.App.MagicbaneApp β) instance Control.Monad.IO.Class.MonadIO (Magicbane.App.MagicbaneApp β) instance GHC.Base.Monad (Magicbane.App.MagicbaneApp β) instance GHC.Base.Applicative (Magicbane.App.MagicbaneApp β) instance GHC.Base.Functor (Magicbane.App.MagicbaneApp β) instance Control.Monad.Trans.Control.MonadBaseControl GHC.Types.IO (Magicbane.App.MagicbaneApp β) -- | A Dropwizard-inspired web framework that integrates Servant, -- monad-metricsEKG, monad-loggerfast-logger, and other useful -- libraries to provide a smooth web service development experience. -- -- This module provides a ClassyPrelude based prelude with all the stuff -- you need reexported. module Magicbane type Host = Header "Host" Text type Form = ReqBody '[FormUrlEncoded] [(Text, Text)] type HTTPLink = Link type WithLink α = Headers '[Header "Link" [HTTPLink]] α decodeEnvy :: FromEnv a => IO (Maybe a) -- | Reads an Envy configuration from the env variables and launches the -- given action if successful. (Does environment variable reading ever -- fail in practice? Probably not.) withEnvConfig :: FromEnv α => (α -> IO ()) -> IO () hPutStrLn :: MonadIO m => Handle -> String -> m () type BasicContext = (ModHttpClient, ModLogger) type BasicApp α = MagicbaneApp BasicContext α newBasicContext :: IO BasicContext instance Data.Default.Class.Default α => System.Envy.DefConfig α