# Elm HTTP stream/chunk handling -- Elm n00b

**URL:** <https://discourse.elm-lang.org/t/elm-http-stream-chunk-handling-elm-n00b/9487>\
**Category:** Learn\
**Created:** [November 27, 2023, 10:20pm UTC](https://discourse.elm-lang.org/t/elm-http-stream-chunk-handling-elm-n00b/9487 "2023-11-27T22:20:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Smyth](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/james_smyth/32/5073_2.png) [@James\_Smyth](https://discourse.elm-lang.org/u/James_Smyth)\
**Post date:** [November 27, 2023, 10:20pm UTC](https://discourse.elm-lang.org/t/elm-http-stream-chunk-handling-elm-n00b/9487/1 "2023-11-27T22:20:32Z")

</div>

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)](https://guide.elm-lang.org/interop/ports.html) 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  
…  
12  
ChunkLength12InHex  
XX  
ChunkLengthXXInHex…etc  
…  
0D  
DoneIndicator

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())  
.getReader();  
while (true) {  
var { chunk, done } = await reader.read();  
if (done) break;  
DoSomethingWithChunk(chunk)  
}  
)

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.

Thanks,  
James

---

<div class="post-metadata">

**Author:** ![szubtsovskiy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/szubtsovskiy/32/900_2.png) [@szubtsovskiy](https://discourse.elm-lang.org/u/szubtsovskiy)\
**Post date:** [November 30, 2023, 8:04am UTC](https://discourse.elm-lang.org/t/elm-http-stream-chunk-handling-elm-n00b/9487/2 "2023-11-30T08:04:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [December 10, 2023, 8:05am UTC](https://discourse.elm-lang.org/t/elm-http-stream-chunk-handling-elm-n00b/9487/3 "2023-12-10T08:05:01Z")

</div>

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