http-client-websockets-0.1.1.3: Glue code for http-client and websockets
Safe HaskellNone
LanguageHaskell2010

Network.HTTP.Client.WebSockets

Description

Glue code for http-client and websockets.

This module is intended to be imported qualified.

If you want to use TLS-secured WebSockets (via the wss scheme) you need to supply a Manager which supports TLS, for example from http-client-tls or http-client-openssl.

Example

>>> :set -XOverloadedStrings
>>> :set -XQuasiQuotes
>>> 
>>> import Network.HTTP.Client (Manager, defaultManagerSettings, newManager)
>>> import qualified Network.WebSockets as WS
>>> import qualified Network.HTTP.Client.WebSockets as HCWS
>>> import Network.URI.Static
>>> import Data.ByteString (ByteString)
>>> 
>>> :{
    runEchoExample :: Manager -> IO ByteString
    runEchoExample mgr = HCWS.runClient mgr echoUri $ \conn -> do
        WS.sendTextData conn ("hello there" :: ByteString)
        _ <- WS.receiveDataMessage conn -- skip first msg
        msg <- WS.receiveData conn
        pure (msg :: ByteString)
      where
        echoUri = [uri|ws://echo.websocket.events|] -- no TLS in this example
:}
>>> runEchoExample =<< newManager defaultManagerSettings
"hello there"

Documentation

runClient Source #

Arguments

:: Manager

Manager to use to establish the connection

-> URI

URI to connect to. Only the schemes ws and wss are valid.

-> ClientApp a

Client application

-> IO a 

runClientWith Source #

Arguments

:: Manager

Manager to use to establish the connection

-> URI

URI to connect to. Only the schemes ws and wss are valid.

-> ConnectionOptions

Options

-> Headers

Custom headers to send

-> ClientApp a

Client application

-> IO a 

runClientWithRequest Source #

Arguments

:: Manager

Manager to use to establish the connection

-> Request

Request to use to open the connection, content will be ignored.

-> ConnectionOptions

Options

-> ClientApp a

Client application

-> IO a