niho / elm-stomp / Stomp.Proc

A remote procedure call (the request/response pattern).

import Stomp.Proc
import Stomp.Client

type Msg = Click | Response (Result String (List String))

update : Msg -> State -> (State, Cmd Msg)
update msg state =
    case msg of
        Click ->
            state ! [ getStrings ]

        Response (Ok strings) ->
            ...

        Response (Err _) ->
            ...

getStrings : Cmd Msg
getStrings =
    Stomp.Proc.init "example.strings"
        |> Stomp.Proc.onResponse Response
        |> Stomp.Client.call server

Remote Procedures


type alias RemoteProcedure msg =
Stomp.Internal.Batch.Batch (Stomp.Internal.Proc.Proc msg)

Describes a remote procedure call.

init : String -> RemoteProcedure msg

Construct a remote procedure call with the specified command (queue name).

Headers and Payload

withHeader : Stomp.Internal.Frame.Header -> RemoteProcedure msg -> RemoteProcedure msg

Add a header to the request message.

withHeaders : List Stomp.Internal.Frame.Header -> RemoteProcedure msg -> RemoteProcedure msg

Add multiple headers to the request message.

withPayload : Json.Encode.Value -> RemoteProcedure msg -> RemoteProcedure msg

Add a payload to the request message.

Response

onResponse : Stomp.Internal.Callback.Callback msg -> RemoteProcedure msg -> RemoteProcedure msg

Set a callback to be triggered when the response message is received.

expectJson : (Result String a -> msg) -> Json.Decode.Decoder a -> RemoteProcedure msg -> RemoteProcedure msg

Set a callback to be triggered when the response message is received and a JSON decoder to be used to decode the message body.

Batching

batch : List (RemoteProcedure msg) -> RemoteProcedure msg

Batch multiple remote procedure calls together.

none : RemoteProcedure msg

Return a remote procedure call that does nothing.