Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Web.Hyperbole.Application
Synopsis
- waiApp :: ServerOptions -> Eff '[Hyperbole, Concurrent, IOE] Response -> Application
- websocketsOr :: ConnectionOptions -> ServerApp -> Application -> Application
- defaultConnectionOptions :: ConnectionOptions
- liveApp :: (ByteString -> ByteString) -> Eff '[Hyperbole, Concurrent, IOE] Response -> Application
- liveAppWith :: ServerOptions -> Eff '[Hyperbole, Concurrent, IOE] Response -> Application
- data ServerOptions = ServerOptions {}
- defaultErrorMessage :: ResponseError -> Text
- defaultError :: ResponseError -> ServerError
- socketApp :: ServerOptions -> Request -> Eff '[Hyperbole, Concurrent, IOE] Response -> PendingConnection -> IO ()
- quickStartDocument :: ByteString -> ByteString
- routeRequest :: (Hyperbole :> es, Route route) => (route -> Eff es Response) -> Eff es Response
Documentation
waiApp :: ServerOptions -> Eff '[Hyperbole, Concurrent, IOE] Response -> Application Source #
websocketsOr :: ConnectionOptions -> ServerApp -> Application -> Application #
Upgrade a websockets
ServerApp
to a wai
Application
. Uses
the given backup Application
to handle Request
s that are not
WebSocket requests.
websocketsOr opts ws_app backup_app = \req respond -> casewebsocketsApp
opts ws_app req ofNothing
-> backup_app req send_responseJust
res -> respond res
For example, below is an Application
that sends "Hello, client!"
to
each connected client.
app ::Application
app =websocketsOr
defaultConnectionOptions
wsApp backupApp where wsApp ::ServerApp
wsApp pending_conn = do conn <-acceptRequest
pending_connsendTextData
conn ("Hello, client!" ::Text
) backupApp ::Application
backupApp _ respond = respond $responseLBS
status400
[] "Not a WebSocket request"
defaultConnectionOptions :: ConnectionOptions #
The default connection options:
- Nothing happens when a pong is received.
- Compression is disabled.
- Lenient unicode decoding.
- 30 second timeout for connection establishment.
liveApp :: (ByteString -> ByteString) -> Eff '[Hyperbole, Concurrent, IOE] Response -> Application Source #
Turn one or more Page
s into a Wai Application. Respond using both HTTP and WebSockets
main :: IO () main = do run 3000 $ do liveApp quickStartDocument (runPage page)
liveAppWith :: ServerOptions -> Eff '[Hyperbole, Concurrent, IOE] Response -> Application Source #
Run a Hyperbole application, customizing both the document and the format of server errors
data ServerOptions Source #
Constructors
ServerOptions | |
Fields
|
socketApp :: ServerOptions -> Request -> Eff '[Hyperbole, Concurrent, IOE] Response -> PendingConnection -> IO () Source #
quickStartDocument :: ByteString -> ByteString Source #
A simple mobile-friendly document with all required embeds and live reload
liveApp
quickStartDocument (routeRequest
router)
routeRequest :: (Hyperbole :> es, Route route) => (route -> Eff es Response) -> Eff es Response Source #
Route URL patterns to different pages
import Example.Docs.Page
.Messages qualified as Messages import Example.Docs.Page
.Users qualified as Users type UserId = Int data AppRoute = Main | Messages | User UserId deriving (Eq, Generic) instanceRoute
AppRoute where baseRoute = Just Main router :: (Hyperbole
:> es) => AppRoute ->Eff
esResponse
router Messages =runPage
Messages.page router (User cid) =runPage
$ Users.page cid router Main = do pure $ view $ doel
"click a link below to visit a page"route
Messages "Messages"route
(User 1) "User 1"route
(User 2) "User 2"