Safe Haskell | None |
---|---|
Language | GHC2021 |
Web.Hyperbole.Application
Synopsis
- waiApp :: (ByteString -> ByteString) -> Eff '[Hyperbole, Server, Concurrent, IOE] Response -> Application
- websocketsOr :: ConnectionOptions -> ServerApp -> Application -> Application
- defaultConnectionOptions :: ConnectionOptions
- liveApp :: (ByteString -> ByteString) -> Eff '[Hyperbole, Server, Concurrent, IOE] Response -> Application
- socketApp :: forall (es :: [Effect]). (IOE :> es, Concurrent :> es) => Eff (Hyperbole ': (Server ': es)) Response -> PendingConnection -> Eff es ()
- basicDocument :: Text -> ByteString -> ByteString
- routeRequest :: forall (es :: [Effect]) route. (Hyperbole :> es, Route route) => (route -> Eff es Response) -> Eff es Response
Documentation
waiApp :: (ByteString -> ByteString) -> Eff '[Hyperbole, Server, 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, Server, Concurrent, IOE] Response -> Application Source #
Turn one or more Page
s into a Wai Application. Respond using both HTTP and WebSockets
#EMBED Example/Docs/BasicPage.hs main
socketApp :: forall (es :: [Effect]). (IOE :> es, Concurrent :> es) => Eff (Hyperbole ': (Server ': es)) Response -> PendingConnection -> Eff es () Source #
basicDocument :: Text -> ByteString -> ByteString Source #
wrap HTML fragments in a simple document with a custom title and include required embeds
liveApp
(basicDocument "App Title") (routeRequest
router)
You may want to specify a custom document function to import custom javascript, css, or add other information to the <head>
import Data.String.Interpolate (i) import Web.Hyperbole (scriptEmbed, cssResetEmbed) #EMBED Example/Docs/App.hs customDocument
routeRequest :: forall (es :: [Effect]) route. (Hyperbole :> es, Route route) => (route -> Eff es Response) -> Eff es Response Source #
Route URL patterns to different pages
#EMBED ExampleDocsApp.hs import Example.Docs.Page #EMBED ExampleDocsApp.hs type UserId #EMBED ExampleDocsApp.hs data AppRoute #EMBED ExampleDocsApp.hs instance Route #EMBED ExampleDocsApp.hs router