Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- newtype Host = Host {
- text :: ByteString
- data Request = Request {
- host :: Host
- path :: [Segment]
- query :: Query
- body :: ByteString
- method :: Method
- cookies :: [(ByteString, ByteString)]
- data Response
- data ResponseError
- newtype Page es a = Page (Eff es a)
- data Event id act = Event {}
- data Server :: Effect where
- LoadRequest :: Server m Request
- SendResponse :: Session -> Response -> Server m ()
- data Hyperbole :: Effect where
- GetRequest :: Hyperbole m Request
- RespondEarly :: Response -> Hyperbole m a
- SetSession :: ToHttpApiData a => Text -> a -> Hyperbole m ()
- DelSession :: Text -> Hyperbole m ()
- GetSession :: FromHttpApiData a => Text -> Hyperbole m (Maybe a)
- data HyperState = HyperState {}
- runHyperbole :: Server :> es => Eff (Hyperbole : es) Response -> Eff es Response
- request :: Hyperbole :> es => Eff es Request
- reqPath :: Hyperbole :> es => Eff es [Segment]
- formData :: Hyperbole :> es => Eff es Form
- getEvent :: (HyperView id, Hyperbole :> es) => Eff es (Maybe (Event id (Action id)))
- parseEvent :: HyperView id => Query -> Maybe (Event id (Action id))
- lookupEvent :: Query -> Maybe (Event Text Text)
- session :: (Hyperbole :> es, FromHttpApiData a) => Text -> Eff es (Maybe a)
- setSession :: (Hyperbole :> es, ToHttpApiData a) => Text -> a -> Eff es ()
- clearSession :: Hyperbole :> es => Text -> Eff es ()
- reqParams :: Hyperbole :> es => Eff es Query
- lookupParam :: ByteString -> Query -> Maybe Text
- reqParam :: (Hyperbole :> es, FromHttpApiData a) => Text -> Eff es a
- notFound :: Hyperbole :> es => Eff es a
- parseError :: Hyperbole :> es => Text -> Eff es a
- redirect :: Hyperbole :> es => Url -> Eff es a
- respondEarly :: (Hyperbole :> es, HyperView id) => id -> View id () -> Eff es ()
- view :: Hyperbole :> es => View () () -> Eff es Response
- load :: Hyperbole :> es => Eff es (View () ()) -> Page es Response
- handle :: forall id es. (Hyperbole :> es, HyperView id) => (id -> Action id -> Eff es (View id ())) -> Page es ()
- page :: Hyperbole :> es => Page es Response -> Eff es Response
Documentation
Host | |
|
Request | |
|
data ResponseError Source #
Instances
Show ResponseError Source # | |
Defined in Web.Hyperbole.Effect showsPrec :: Int -> ResponseError -> ShowS # show :: ResponseError -> String # showList :: [ResponseError] -> ShowS # |
Hyperbole applications are divided into Pages. Each Page must load
the whole page , and handle
each type of HyperView
myPage :: (Hyperbole
:> es) =>Page
esResponse
myPage = dohandle
messagesload
pageView pageView = do el_ "My Page"hyper
(Message 1) $ messageView "Starting Message"
An action, with its corresponding id
data Server :: Effect where Source #
Low level effect mapping request/response to either HTTP or WebSockets
LoadRequest :: Server m Request | |
SendResponse :: Session -> Response -> Server m () |
Instances
type DispatchOf Server Source # | |
Defined in Web.Hyperbole.Effect |
data Hyperbole :: Effect where Source #
In any load
or handle
, you can use this Effect to get extra request information or control the response manually.
For most Page
s, you won't need to use this effect directly. Use custom Route
s for request info, and return View
s to respond
GetRequest :: Hyperbole m Request | |
RespondEarly :: Response -> Hyperbole m a | |
SetSession :: ToHttpApiData a => Text -> a -> Hyperbole m () | |
DelSession :: Text -> Hyperbole m () | |
GetSession :: FromHttpApiData a => Text -> Hyperbole m (Maybe a) |
Instances
type DispatchOf Hyperbole Source # | |
Defined in Web.Hyperbole.Effect |
data HyperState Source #
reqPath :: Hyperbole :> es => Eff es [Segment] Source #
Return the request path
>>>
reqPath
["users", "100"]
formData :: Hyperbole :> es => Eff es Form Source #
Return the request body as a Web.FormUrlEncoded.Form
Prefer using Type-Safe Form
s when possible
session :: (Hyperbole :> es, FromHttpApiData a) => Text -> Eff es (Maybe a) Source #
Lookup a session variable by keyword
load $ do tok <- session "token" ...
setSession :: (Hyperbole :> es, ToHttpApiData a) => Text -> a -> Eff es () Source #
Set a session variable by keyword
load $ do t <- reqParam "token" setSession "token" t ...
reqParams :: Hyperbole :> es => Eff es Query Source #
Return the entire Query
myPage ::Page
esResponse
myPage = doload
$ do q <- reqParams caselookupParam
"token" q of Nothing -> pure $ errorView "Missing Token in Query String" Just t -> do sideEffectUsingToken token pure myPageView
lookupParam :: ByteString -> Query -> Maybe Text Source #
Lookup the query param in the Query
notFound :: Hyperbole :> es => Eff es a Source #
Respond immediately with 404 Not Found
userLoad :: (Hyperbole :> es, Users :> es) => UserId -> Eff es User userLoad uid = do mu <- send (LoadUser uid) maybe notFound pure mu myPage :: (Hyperbole :> es, Users :> es) => Eff es View myPage = do load $ do u <- userLoad 100 -- skipped if user = Nothing pure $ userView u
respondEarly :: (Hyperbole :> es, HyperView id) => id -> View id () -> Eff es () Source #
Respond with the given view, and stop execution
load :: Hyperbole :> es => Eff es (View () ()) -> Page es Response Source #
The load handler is run when the page is first loaded. Run any side effects needed, then return a view of the full page
myPage :: (Hyperbole :> es) => UserId -> Page es Response
myPage userId = do
load
$ do
user <- loadUserFromDatabase userId
pure $ userPageView user
handle :: forall id es. (Hyperbole :> es, HyperView id) => (id -> Action id -> Eff es (View id ())) -> Page es () Source #
A handler is run when an action for that HyperView
is triggered. Run any side effects needed, then return a view of the corresponding type
myPage :: (Hyperbole
:> es) =>Page
esResponse
myPage = dohandle
messagesload
pageView messages :: (Hyperbole
:> es, MessageDatabase) => Message -> MessageAction ->Eff
es (View
Message ()) messages (Message mid) ClearMessage = do deleteMessageSideEffect mid pure $ messageView "" messages (Message mid) (Louder m) = do let new = m <> "!" saveMessageSideEffect mid new pure $ messageView new