Elm HTTP stream/chunk handling -- Elm n00b

I’ve done a fair amount of research (ie. googling) and I’m not finding simple examples of how to use the Elm HTTP package, with what I think is the common paradigm, to process an http stream delivered in chunks(***). I’ve seen a few things indicating that I might have to do it using javascript (which i know quite well) and ports ( Ports · An Introduction to Elm (elm-lang.org) eh?), or maybe a ServiceWorker (familiar w/ that). I just want to make sure that there isn’t a prototypical way to do this in Elm that I haven’t stumbed on yet.

(*** There seems to be a fair amount of ambiguity on the interwebs about what https streaming/chunking means. My API responds w/

Content-Type: text/event-stream; charset=utf-8
Transfer-Encoding: chunked



Which i can consume easily via fetch (NB: I’m aware that Elm HTTP package doesn’t use fetch…)
const reader = fetchResponse.body
.pipeThrough(new TextDecoderStream())
while (true) {
var { chunk, done } = await reader.read();
if (done) break;

If I have to figure out how to implement this w/out using Elm HTTP, that’s fine, but I thought this might be a good place to ask for help to do it the correct way.


Hi James,

My understanding is that you will need to use ports to achieve what you want. That’s what I would definitely do if I was solving a similar task.

Elm HTTP package provides a few handy functions to track progress but it won’t give you access to chunks, I believe, only to the number of bytes sent/received.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.