Safe Haskell | None |
---|---|
Language | Haskell2010 |
- Type
Server
- Type
ServerRes
- Type
ServerResStream
- Type
Router
- Orphan instances
See symantic-http-demo for an example of how to use this module.
Synopsis
- newtype Server handlers k = Server {
- unServer :: StateT ServerState (ServerCheckT [ServerErrorBody] (ServerCheckT [ServerErrorHeader] (ServerCheckT [ServerErrorQuery] (ServerCheckT [ServerErrorContentType] (ServerCheckT [ServerErrorAccept] (ServerCheckT [ServerErrorBasicAuth] (ServerCheckT [ServerErrorMethod] (ServerCheckT [ServerErrorPath] IO)))))))) (handlers -> k)
- server :: Router Server handlers (Response Server) -> handlers -> Application
- runServerChecks :: StateT ServerState (ExceptT e1 (ExceptT e2 (ExceptT e3 (ExceptT e4 (ExceptT e5 (ExceptT e6 (ExceptT e7 (ExceptT e8 IO)))))))) a -> ServerState -> IO (Either e8 (Either e7 (Either e6 (Either e5 (Either e4 (Either e3 (Either e2 (Either e1 (a, ServerState)))))))))
- type ServerCheckT e = ExceptT (Fail e)
- type RouteResult e = Either (Fail e)
- data Fail e
- = Fail ServerState e
- | FailFatal !ServerState !e
- failState :: Fail e -> ServerState
- failError :: Fail e -> e
- newtype ServerState = ServerState {}
- newtype ServerErrorPath = ServerErrorPath Text
- data ServerErrorMethod = ServerErrorMethod
- data ServerErrorAccept = ServerErrorAccept MediaTypes (Maybe (Either ByteString MediaType))
- data ServerErrorContentType = ServerErrorContentType
- newtype ServerErrorQuery = ServerErrorQuery Text
- data ServerErrorHeader = ServerErrorHeader
- data ServerErrorBasicAuth = ServerErrorBasicAuth BasicAuthRealm (BasicAuth ())
- class ServerBasicAuth a where
- serverBasicAuth :: BasicAuthUser -> BasicAuthPass -> IO (BasicAuth a)
- newtype ServerErrorBody = ServerErrorBody String
- newtype ServerBodyArg (ts :: [Type]) a = ServerBodyArg a
- newtype ServerBodyStreamArg as (ts :: [Type]) framing = ServerBodyStreamArg as
- newtype ServerRes (ts :: [Type]) m a = ServerResponse {
- unServerResponse :: m a
- type ServerResponse ts m = ServerRes ts (ReaderT Request (WriterT ResponseHeaders (WriterT Status (ContT Response m))))
- newtype ServerResStream framing (ts :: [Type]) m as = ServerResponseStream {
- unServerResponseStream :: m as
- type ServerResponseStream framing ts m = ServerResStream framing ts (ReaderT Request (WriterT ResponseHeaders (WriterT Status (ContT Response m))))
- data Router repr a b where
- Router_Any :: repr a b -> Router repr a b
- Router_Seg :: PathSegment -> Router repr k k
- Router_Cat :: Router repr a b -> Router repr b c -> Router repr a c
- Router_Map :: Map PathSegment (Router repr a k) -> Router repr a k
- Router_Alt :: Router repr a k -> Router repr b k -> Router repr (a :!: b) k
- Router_Cap :: PathConstraint Server a => Name -> Router repr (a -> k) k
- Router_Caps :: Captures (Router repr) cs k -> Router repr (AltFromBinTree cs) k
- Router_Union :: (b -> a) -> Router repr a k -> Router repr b k
- data Captures repr (cs :: BinTree Type) k where
- data BinTree a
- type family AltFromBinTree (cs :: BinTree Type) :: Type where ...
- class HTTP_Routing repr where
- routing :: Map PathSegment (repr a k) -> repr a k
- captures :: Captures repr cs k -> repr (AltFromBinTree cs) k
- router :: Router repr a b -> Router repr a b
- router_Alt :: Router repr a k -> Router repr b k -> Router repr (a :!: b) k
- router_Map :: Map PathSegment (Router repr a k) -> Map PathSegment (Router repr b k) -> Router repr (a :!: b) k
Type Server
newtype Server handlers k Source #
(
) is a recipe to produce an Server
handlers kApplication
from given (handlers
) (one per number of alternative routes),
separated by (:!:
).
Server
is analogous to a scanf using the API as a format customized for HTTP routing.
The multiple ServerCheckT
monad transformers are there
to prioritize the errors according to the type of check raising them,
instead of the order of the combinators within an actual API specification.
Server | |
|
Instances
server :: Router Server handlers (Response Server) -> handlers -> Application Source #
(
) returns an server
api handlersApplication
ready to be given to Warp.run 80
.
runServerChecks :: StateT ServerState (ExceptT e1 (ExceptT e2 (ExceptT e3 (ExceptT e4 (ExceptT e5 (ExceptT e6 (ExceptT e7 (ExceptT e8 IO)))))))) a -> ServerState -> IO (Either e8 (Either e7 (Either e6 (Either e5 (Either e4 (Either e3 (Either e2 (Either e1 (a, ServerState))))))))) Source #
Type ServerCheckT
type ServerCheckT e = ExceptT (Fail e) Source #
Type RouteResult
type RouteResult e = Either (Fail e) Source #
Type Fail
Fail ServerState e | Keep trying other paths. 404, 405 or 406. |
FailFatal !ServerState !e | Don't try other paths. |
failState :: Fail e -> ServerState Source #
Type ServerState
newtype ServerState Source #
Instances
Show ServerState Source # | |
Defined in Symantic.HTTP.Server showsPrec :: Int -> ServerState -> ShowS # show :: ServerState -> String # showList :: [ServerState] -> ShowS # |
Type ServerErrorPath
newtype ServerErrorPath Source #
Instances
Eq ServerErrorPath Source # | |
Defined in Symantic.HTTP.Server (==) :: ServerErrorPath -> ServerErrorPath -> Bool # (/=) :: ServerErrorPath -> ServerErrorPath -> Bool # | |
Show ServerErrorPath Source # | |
Defined in Symantic.HTTP.Server showsPrec :: Int -> ServerErrorPath -> ShowS # show :: ServerErrorPath -> String # showList :: [ServerErrorPath] -> ShowS # |
Type ServerErrorMethod
data ServerErrorMethod Source #
Instances
Eq ServerErrorMethod Source # | |
Defined in Symantic.HTTP.Server (==) :: ServerErrorMethod -> ServerErrorMethod -> Bool # (/=) :: ServerErrorMethod -> ServerErrorMethod -> Bool # | |
Show ServerErrorMethod Source # | |
Defined in Symantic.HTTP.Server showsPrec :: Int -> ServerErrorMethod -> ShowS # show :: ServerErrorMethod -> String # showList :: [ServerErrorMethod] -> ShowS # |
Type ServerErrorAccept
data ServerErrorAccept Source #
Instances
Eq ServerErrorAccept Source # | |
Defined in Symantic.HTTP.Server (==) :: ServerErrorAccept -> ServerErrorAccept -> Bool # (/=) :: ServerErrorAccept -> ServerErrorAccept -> Bool # | |
Show ServerErrorAccept Source # | |
Defined in Symantic.HTTP.Server showsPrec :: Int -> ServerErrorAccept -> ShowS # show :: ServerErrorAccept -> String # showList :: [ServerErrorAccept] -> ShowS # |
Type ServerErrorContentType
data ServerErrorContentType Source #
Instances
Eq ServerErrorContentType Source # | |
Defined in Symantic.HTTP.Server | |
Show ServerErrorContentType Source # | |
Defined in Symantic.HTTP.Server showsPrec :: Int -> ServerErrorContentType -> ShowS # show :: ServerErrorContentType -> String # showList :: [ServerErrorContentType] -> ShowS # |
Type ServerErrorQuery
newtype ServerErrorQuery Source #
Instances
Show ServerErrorQuery Source # | |
Defined in Symantic.HTTP.Server showsPrec :: Int -> ServerErrorQuery -> ShowS # show :: ServerErrorQuery -> String # showList :: [ServerErrorQuery] -> ShowS # |
Type ServerErrorHeader
data ServerErrorHeader Source #
Instances
Eq ServerErrorHeader Source # | |
Defined in Symantic.HTTP.Server (==) :: ServerErrorHeader -> ServerErrorHeader -> Bool # (/=) :: ServerErrorHeader -> ServerErrorHeader -> Bool # | |
Show ServerErrorHeader Source # | |
Defined in Symantic.HTTP.Server showsPrec :: Int -> ServerErrorHeader -> ShowS # show :: ServerErrorHeader -> String # showList :: [ServerErrorHeader] -> ShowS # |
Type ServerErrorBasicAuth
data ServerErrorBasicAuth Source #
Instances
Show ServerErrorBasicAuth Source # | |
Defined in Symantic.HTTP.Server showsPrec :: Int -> ServerErrorBasicAuth -> ShowS # show :: ServerErrorBasicAuth -> String # showList :: [ServerErrorBasicAuth] -> ShowS # |
Class ServerBasicAuth
class ServerBasicAuth a where Source #
Custom BasicAuth
check.
serverBasicAuth :: BasicAuthUser -> BasicAuthPass -> IO (BasicAuth a) Source #
Type ServerErrorBody
newtype ServerErrorBody Source #
Instances
Eq ServerErrorBody Source # | |
Defined in Symantic.HTTP.Server (==) :: ServerErrorBody -> ServerErrorBody -> Bool # (/=) :: ServerErrorBody -> ServerErrorBody -> Bool # | |
Show ServerErrorBody Source # | |
Defined in Symantic.HTTP.Server showsPrec :: Int -> ServerErrorBody -> ShowS # show :: ServerErrorBody -> String # showList :: [ServerErrorBody] -> ShowS # |
Type ServerBodyArg
newtype ServerBodyArg (ts :: [Type]) a Source #
Type ServerBodyStreamArg
newtype ServerBodyStreamArg as (ts :: [Type]) framing Source #
Type ServerRes
newtype ServerRes (ts :: [Type]) m a Source #
A continuation for server'
s users to respond.
This newtype has two uses :
ServerResponse | |
|
Instances
MonadTrans (ServerRes ts) Source # | |
Defined in Symantic.HTTP.Server | |
Monad m => Monad (ServerRes ts m) Source # | |
Functor m => Functor (ServerRes ts m) Source # | |
Applicative m => Applicative (ServerRes ts m) Source # | |
Defined in Symantic.HTTP.Server pure :: a -> ServerRes ts m a # (<*>) :: ServerRes ts m (a -> b) -> ServerRes ts m a -> ServerRes ts m b # liftA2 :: (a -> b -> c) -> ServerRes ts m a -> ServerRes ts m b -> ServerRes ts m c # (*>) :: ServerRes ts m a -> ServerRes ts m b -> ServerRes ts m b # (<*) :: ServerRes ts m a -> ServerRes ts m b -> ServerRes ts m a # | |
type CanDo (ServerResponse ts m) (eff :: Type) Source # | All supported effects are handled by nested |
Defined in Symantic.HTTP.Server |
type ServerResponse ts m = ServerRes ts (ReaderT Request (WriterT ResponseHeaders (WriterT Status (ContT Response m)))) Source #
Type ServerResStream
newtype ServerResStream framing (ts :: [Type]) m as Source #
Instances
MonadTrans (ServerResStream framing ts) Source # | |
Defined in Symantic.HTTP.Server lift :: Monad m => m a -> ServerResStream framing ts m a # | |
Monad m => Monad (ServerResStream framing ts m) Source # | |
Defined in Symantic.HTTP.Server (>>=) :: ServerResStream framing ts m a -> (a -> ServerResStream framing ts m b) -> ServerResStream framing ts m b # (>>) :: ServerResStream framing ts m a -> ServerResStream framing ts m b -> ServerResStream framing ts m b # return :: a -> ServerResStream framing ts m a # fail :: String -> ServerResStream framing ts m a # | |
Functor m => Functor (ServerResStream framing ts m) Source # | |
Defined in Symantic.HTTP.Server fmap :: (a -> b) -> ServerResStream framing ts m a -> ServerResStream framing ts m b # (<$) :: a -> ServerResStream framing ts m b -> ServerResStream framing ts m a # | |
Applicative m => Applicative (ServerResStream framing ts m) Source # | |
Defined in Symantic.HTTP.Server pure :: a -> ServerResStream framing ts m a # (<*>) :: ServerResStream framing ts m (a -> b) -> ServerResStream framing ts m a -> ServerResStream framing ts m b # liftA2 :: (a -> b -> c) -> ServerResStream framing ts m a -> ServerResStream framing ts m b -> ServerResStream framing ts m c # (*>) :: ServerResStream framing ts m a -> ServerResStream framing ts m b -> ServerResStream framing ts m b # (<*) :: ServerResStream framing ts m a -> ServerResStream framing ts m b -> ServerResStream framing ts m a # | |
type CanDo (ServerResponseStream framing ts m) (eff :: Type) Source # | All supported effects are handled by nested |
Defined in Symantic.HTTP.Server |
type ServerResponseStream framing ts m = ServerResStream framing ts (ReaderT Request (WriterT ResponseHeaders (WriterT Status (ContT Response m)))) Source #
Type Router
data Router repr a b where Source #
Router_Any :: repr a b -> Router repr a b | Lift any |
Router_Seg :: PathSegment -> Router repr k k | Represent |
Router_Cat :: Router repr a b -> Router repr b c -> Router repr a c | Represent ( |
Router_Map :: Map PathSegment (Router repr a k) -> Router repr a k | Represent |
Router_Alt :: Router repr a k -> Router repr b k -> Router repr (a :!: b) k | Represent ( |
Router_Cap :: PathConstraint Server a => Name -> Router repr (a -> k) k | Represent |
Router_Caps :: Captures (Router repr) cs k -> Router repr (AltFromBinTree cs) k | Represent |
Router_Union :: (b -> a) -> Router repr a k -> Router repr b k | Unify |
Instances
Type Captures
Type BinTree
Type family AltFromBinTree
type family AltFromBinTree (cs :: BinTree Type) :: Type where ... Source #
AltFromBinTree (BinTree0 x) = x | |
AltFromBinTree (BinTree2 x y) = AltFromBinTree x :!: AltFromBinTree y |
Class HTTP_Routing
class HTTP_Routing repr where Source #
Nothing
routing :: Map PathSegment (repr a k) -> repr a k Source #
captures :: Captures repr cs k -> repr (AltFromBinTree cs) k Source #
routing :: Trans repr => HTTP_Routing (UnTrans repr) => Map PathSegment (repr a k) -> repr a k Source #
captures :: Trans repr => HTTP_Routing (UnTrans repr) => Captures repr cs k -> repr (AltFromBinTree cs) k Source #
Instances
HTTP_Routing Server Source # | |
Defined in Symantic.HTTP.Server | |
HTTP_Routing (Router Server) Source # | |
router :: Router repr a b -> Router repr a b Source #
Traverse a Router
to transform it:
- Associate
Router_Cat
to the right. - Replace
Router_Seg
withRouter_Map
. - Replace
Router_Cap
withRouter_Caps
.
router_Alt :: Router repr a k -> Router repr b k -> Router repr (a :!: b) k Source #
Merge/reorder alternatives if possible or default to a Router_Alt
.
router_Map :: Map PathSegment (Router repr a k) -> Map PathSegment (Router repr b k) -> Router repr (a :!: b) k Source #