How to use `Req` to handle chunked responses from a GET request?

Using Req, I’m making a GET request to microsoft’s graph API which it returns a result with the following header: "transfer-encoding" => ["chunked"], and a partial response.

After some looking around, I found this post: Handling http response streaming - #2 by garrison, which says I should be using the into: option.

So my request now looks like this:

    Req.get("https://graph.microsoft.com/v1.0/me/events?$expand=extensions",
      headers: ...,
      into: fn {:data, data}, {req, resp} ->
        IO.inspect(data, label: "data")
        resp = Req.Request.update_private(resp, :chunked_response, [data], &[data | &1])
        {:cont, {req, resp}}
      end
    )

However, it seems it’s not continuing. The iteration only calls once, with a very partial bit of json

data: "{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('xxxxxx')/events(extensions())\",\"value\":["

Im wondering if anyone more famaliar with Req can point out any blunder I might of made?


The full response from the Req.get

{:ok,
 %Req.Response{
   status: 200,
   headers: %{
     "cache-control" => ["private"],
     "client-request-id" => ["xxxxxxxx"],
     "content-type" => ["application/json; odata.metadata=minimal; odata.streaming=true; IEEE754Compatible=false; charset=utf-8"],
     "date" => ["Tue, 10 Jun 2025 17:43:01 GMT"],
     "request-id" => ["xxxxxxx"],
     "strict-transport-security" => ["max-age=31536000"],
     "transfer-encoding" => ["chunked"],
     "x-ms-ags-diagnostic" => ["{\"ServerInfo\":{\"DataCenter\":\"UK South\",\"Slice\":\"E\",\"Ring\":\"5\",\"ScaleUnit\":\"006\",\"RoleInstance\":\"LN2PEPF00013DFE\"}}"]
   },
   body: "",
   trailers: %{},
   private: %{
     chunked_response: ["{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('xxxxxx')/events(extensions())\",\"value\":["]
   }
 }}

(I’ve swapped out any ID’s for xxxxxx)

Using https://httpbin.org/stream/2 as a source, the code works as expected, check the intermediate req and resp values

1 Like

Things I looked into:

  1. Your code looks just fine
  2. Nothing i see amiss in Req itself
  3. Nothing I see weird in finch
  4. There’s a lot of issues with Microsoft IIS dealing with transfer encoding - given the service your connecting to is version 1 - I bet they haven’t set something up right.
  5. Going further might be just unpaid QA for microsoft.
1 Like

I’ve had a look at the intermediate req and resp values, and although im not too sure what I’m looking for, nothing stood out to me.

But this gave me an idea, what if it’s not the code at all!

So I tried to get it work with Postman or Graph Explorer | Try Microsoft Graph APIs - Microsoft Graph, but they also get the same malformed data…

So I’m wondering if the microsoft API is just straight up returning malformed data for me? :frowning:


Ah, this came through as I was typing this response. Thank you for checking. Microsoft is gonna cause me hair loss I swear :smiling_face_with_tear:


Thank you for the responses, I shall go communicate with a microsoft AI support chatbot for 12 hours hoping to get this resolved :sweat_smile:

3 Likes