servant-websockets-1.1.0: Small library providing WebSocket endpoints for servant.

Safe HaskellNone
LanguageHaskell2010

Servant.API.WebSocketConduit

Synopsis

Documentation

data WebSocketConduit i o #

Endpoint for defining a route to provide a websocket. In contrast to the WebSocket endpoint, WebSocketConduit provides a higher-level interface. The handler function must be of type Conduit i m o with i and o being instances of FromJSON and ToJSON respectively. await reads from the web socket while yield writes to it.

Example:

import Data.Aeson (Value)
import qualified Data.Conduit.List as CL

type WebSocketApi = "echo" :> WebSocketConduit Value Value

server :: Server WebSocketApi
server = echo
 where
  echo :: Monad m => Conduit Value m Value
  echo = CL.map id

Note that the input format on the web socket is JSON, hence this example only echos valid JSON data.

Instances
(FromJSON i, ToJSON o) => HasServer (WebSocketConduit i o :: *) ctx # 
Instance details

Defined in Servant.API.WebSocketConduit

Associated Types

type ServerT (WebSocketConduit i o) m :: * #

Methods

route :: Proxy (WebSocketConduit i o) -> Context ctx -> Delayed env (Server (WebSocketConduit i o)) -> Router env #

hoistServerWithContext :: Proxy (WebSocketConduit i o) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (WebSocketConduit i o) m -> ServerT (WebSocketConduit i o) n #

type ServerT (WebSocketConduit i o :: *) m # 
Instance details

Defined in Servant.API.WebSocketConduit

type ServerT (WebSocketConduit i o :: *) m = Conduit i (ResourceT IO) o