Choosing the transport layer: WebSockets or HTTP

By default Stipple will attempt to use WebSockets for real time data sync between backend and frontend. However, in some cases WebSockets support might not be available on the host. In this case, Stipple can be switched to use regular HTTP for data sync, using frontend polling with AJAX (1s polling interval by default). Stipple can be configured to use AJAX/HTTP by passing the transport param to the init() method, ex:

model = Stipple.init(Name, transport = Genie.WebThreads)

The current available options for transport are Genie.WebChannels (default, using WebSockets) and Genie.WebThreads (using HTTP/AJAX).

Given that polling generates quite a number of extra requests, it can be desirable to disable automatic logging of requests. This can be done using Genie.config.log_requests = false.

Here is a full example on how to configure an app to use HTTP/AJAX:

using GenieFramework

Genie.config.log_requests = false

@app Name begin
  @in name = "World!"
end

function ui()
    [
      h1([
        "Hello "
        span("{{name}}")
      ])

      p([
        "What is your name? "
        textfield("", :name, placeholder="Type your name")
      ])
    ]
end

route("/") do
  model = init(Name, transport = Genie.WebThreads)
  page(model, ui()) |> html
end

Genie.isrunning() || up()