wist/adapters/mist

Wist adapter for the Mist web server.

This module implements the transport adapter bridging Mist’s WebSocket upgrade logic and connection actor loops to Wist’s transport-neutral Handler API.

Use upgrade inside your Mist HTTP request handler to switch protocols and run a stateful Wist handler.

Values

pub fn upgrade(
  request: request.Request(mist.Connection),
  handler: wist.Handler(state, inbound, outbound),
  codec: wist.Codec(inbound, outbound),
) -> response.Response(mist.ResponseData)

Upgrades an incoming HTTP request to a WebSocket connection managed by Wist.

If the request is a valid WebSocket handshake request, it returns a 101 Switching Protocols response body configured to spawn Mist’s WebSocket handler process. If the request is malformed or invalid, a 400 Bad Request response is returned.

Parameters

  • request: The incoming HTTP request carrying the Mist transport Connection.
  • handler: The stateful wist.Handler defining initial state and event transitions.
  • codec: A wist.Codec specifying how to encode and decode wire frames.

Guarantees

  • Serialization: Connection events are processed strictly sequentially. update is never run concurrently.
  • FIFO Effects: Effects returned by update are executed in the exact order they are listed.
  • Safety: If frame decoding fails, the connection is closed immediately, and a Failed event is dispatched.

Limitations

  • Outbound pings are supported via the wist.Ping effect, but client Pong frames are swallowed by Mist’s internal wrapper and will not be dispatched as events.

Example

import wist
import wist/adapters/mist as wist_mist

fn my_http_handler(req) {
  case req.path {
    "/ws" -> wist_mist.upgrade(req, my_ws_handler, wist.raw_codec())
    _ -> response.new(200)
  }
}
Search Document