Client code for SSE (Server Sent Events) with HTTP.jl

I’m attempting to receive SSE from a Mastodon instance, following the API described in the official docs.

Firstly, I can’t get to work. Attempting:"get", "$token"; status_exception=false) do io
    while !eof(io)

results in a 400 Bad Request from nginx. However, this:

io = IOBuffer()
r = @async HTTP.get("$token"; response_stream=io, status_exception=false)

works fine and I can then read from IO to access the SSE. What am I doing wrong in the first part? (I’ve tried various combinations of startwrite, closewrite, and startread on IO without success)

Secondly, in the second example, the task r never finishes (istaskdone(r) is always false). Is this a problem if I keep starting tasks like this? Is there some way to end them when I’m done? Or is there a better way in general?

1 Like

Finally figured out that the HTTP methods have to be capitalised. So that should be"GET", ...).