| Safe Haskell | None |
|---|---|
| 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 :: forall (es :: [Effect]) route. (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 Requests that are not
WebSocket requests.
websocketsOr opts ws_app backup_app = \req respond ->
case websocketsApp opts ws_app req of
Nothing -> backup_app req send_response
Just res -> respond res
For example, below is an Application that sends "Hello, client!" to
each connected client.
app ::Applicationapp =websocketsOrdefaultConnectionOptionswsApp backupApp where wsApp ::ServerAppwsApp pending_conn = do conn <-acceptRequestpending_connsendTextDataconn ("Hello, client!" ::Text) backupApp ::ApplicationbackupApp _ respond = respond $responseLBSstatus400[] "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 Pages into a Wai Application. Respond using both HTTP and WebSockets
#EMBED Example/Docs/BasicPage.hs main
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
liveAppquickStartDocument (routeRequestrouter)
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