HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleservant-websockets-2.0.0Haskell2010

Servant.API.WebSocket

  • 2 types
datadata WebSocket
#

Endpoint for defining a route to provide a web socket. The handler function gets an already negotiated websocket Connection to send and receive data.

Example:

type WebSocketApi = "stream" :> WebSocket

server :: Server WebSocketApi
server = streamData
 where
  streamData :: MonadIO m => Connection -> m ()
  streamData c = do
    liftIO $ forkPingThread c 10
    liftIO . forM_ [1..] $ \i -> do
       sendTextData c (pack $ show (i :: Int)) >> threadDelay 1000000
Instances2HasServer, ServerT
datadata WebSocketPending
#

Endpoint for defining a route to provide a web socket. The handler function gets a PendingConnection. It can either rejectRequest or acceptRequest. This function is provided for greater flexibility to reject connections.

Example:

type WebSocketApi = "stream" :> WebSocketPending

server :: Server WebSocketApi
server = streamData
 where
  streamData :: MonadIO m => PendingConnection -> m ()
  streamData pc = do
     c <- acceptRequest pc
     liftIO $ forkPingThread c 10
     liftIO . forM_ [1..] $ \i ->
       sendTextData c (pack $ show (i :: Int)) >> threadDelay 1000000
Instances2HasServer, ServerT