polysemy-webserver-0.2.1.1: Start web servers from within a Polysemy effect stack
Safe HaskellNone
LanguageHaskell2010

Polysemy.WebServer

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.

Instances

Instances details
type DefiningModule WebServer Source # 
Instance details

Defined in Polysemy.WebServer

type DefiningModule WebServer = "Polysemy.WebServer"