polysemy-webserver-0.2.1.2: Start web servers from within a Polysemy effect stack
Safe HaskellSafe-Inferred
LanguageHaskell2010

Polysemy.WebServer

Synopsis

Documentation

data WebServer m a where Source #

Constructors

StartWebServer :: Port -> (Request -> PendingWebRequest -> m ResponseReceived) -> WebServer m ()

Starts a new web-server listening on a port, sending all requests to the provided function.

StartWebServerSettings :: Settings -> (Request -> PendingWebRequest -> m ResponseReceived) -> WebServer m () 
RespondWebRequest :: PendingWebRequest -> Response -> WebServer m ResponseReceived

Responds to a web request (usually called from the callback to StartWebServer.

GetBody :: Int -> Request -> WebServer m (Maybe ByteString)

Reads the entire body of a request into memory. Takes a maximum length to read - if the body length exceeds this length, returns Nothing.

UpgradeToWebSocketsResponse :: ConnectionOptions -> (PendingConnection -> m ()) -> Request -> WebServer m (Maybe Response)

Builds a response to upgrade a connection to a web socket. Returns Nothing if the request is not appropriate to upgrade.

AcceptPendingWebSocketConnection :: PendingConnection -> AcceptRequest -> WebServer m (Either (Either HandshakeException ConnectionException) Connection)

Accepts a pending WebSockets connection.

RejectPendingWebSocketConnection :: PendingConnection -> RejectRequest -> WebServer m ()

Rejects a pending WebSockets connection.

WhilePingingWebSocket :: Connection -> Int -> m a -> WebServer m (Maybe a)

Runs an app, and sends a ping message over the WebSockets connection every n seconds while the app is executing. When the app completes, the pings will also stop.

SendWebSocketDataMessages :: Connection -> [DataMessage] -> WebServer m ()

Sends some data messages over the WebSockets connection.

ReceiveWebSocketDataMessage :: Connection -> WebServer m (Either ConnectionException DataMessage)

Receives a data message from the WebSockets connection. Returns a Left WS.CloseRequest if the connection is closed cleanly. Returns a Left WS.ConnectionClosed if the connection is closed uncleanly.

SendWebSocketCloseCode :: WebSocketsData a => Connection -> Word16 -> a -> WebServer m ()

Sends a friendly close message and close code on a WebSocket. See http://tools.ietf.org/html/rfc6455#section-7.4 for a list of close codes.

startWebServer :: forall r. Member WebServer r => Port -> (Request -> PendingWebRequest -> Sem r ResponseReceived) -> Sem r () Source #

Starts a new web-server listening on a port, sending all requests to the provided function.

respondWebRequest :: forall r. Member WebServer r => PendingWebRequest -> Response -> Sem r ResponseReceived Source #

Responds to a web request (usually called from the callback to StartWebServer.

getBody :: forall r. Member WebServer r => Int -> Request -> Sem r (Maybe ByteString) Source #

Reads the entire body of a request into memory. Takes a maximum length to read - if the body length exceeds this length, returns Nothing.

upgradeToWebSocketsResponse :: forall r. Member WebServer r => ConnectionOptions -> (PendingConnection -> Sem r ()) -> Request -> Sem r (Maybe Response) Source #

Builds a response to upgrade a connection to a web socket. Returns Nothing if the request is not appropriate to upgrade.

rejectPendingWebSocketConnection :: forall r. Member WebServer r => PendingConnection -> RejectRequest -> Sem r () Source #

Rejects a pending WebSockets connection.

whilePingingWebSocket :: forall r a. Member WebServer r => Connection -> Int -> Sem r a -> Sem r (Maybe a) Source #

Runs an app, and sends a ping message over the WebSockets connection every n seconds while the app is executing. When the app completes, the pings will also stop.

sendWebSocketDataMessages :: forall r. Member WebServer r => Connection -> [DataMessage] -> Sem r () Source #

Sends some data messages over the WebSockets connection.

receiveWebSocketDataMessage :: forall r. Member WebServer r => Connection -> Sem r (Either ConnectionException DataMessage) Source #

Receives a data message from the WebSockets connection. Returns a Left WS.CloseRequest if the connection is closed cleanly. Returns a Left WS.ConnectionClosed if the connection is closed uncleanly.

sendWebSocketCloseCode :: forall r a. (Member WebServer r, WebSocketsData a) => Connection -> Word16 -> a -> Sem r () Source #

Sends a friendly close message and close code on a WebSocket. See http://tools.ietf.org/html/rfc6455#section-7.4 for a list of close codes.