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

**URL:** <https://discourse.julialang.org/t/client-code-for-sse-server-sent-events-with-http-jl/110386>\
**Category:** Web Stack\
**Tags:** http, sse\
**Created:** [February 19, 2024, 1:43am UTC](https://discourse.julialang.org/t/client-code-for-sse-server-sent-events-with-http-jl/110386 "2024-02-19T01:43:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![screw\_dog](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/screw_dog/32/48119_2.png) [@screw\_dog](https://discourse.julialang.org/u/screw_dog)\
**Post date:** [February 19, 2024, 1:43am UTC](https://discourse.julialang.org/t/client-code-for-sse-server-sent-events-with-http-jl/110386/1 "2024-02-19T01:43:44Z")

</div>

I’m attempting to receive SSE from a Mastodon instance, following the API described in the [official docs](https://docs.joinmastodon.org/methods/streaming/).

Firstly, I can’t get `HTTP.open` to work. Attempting:

```julia
HTTP.open("get", "https://aus.social/api/v1/streaming/public?access_token=$token"; status_exception=false) do io
    while !eof(io)
        println(String(readavailable(io)))
    end
end

```

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

```julia
io = IOBuffer()
r = @async HTTP.get("https://aus.social/api/v1/streaming/public?access_token=$token"; response_stream=io, status_exception=false)
println(r)

```

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?

---

<div class="post-metadata">

**Author:** ![screw\_dog](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/screw_dog/32/48119_2.png) [@screw\_dog](https://discourse.julialang.org/u/screw_dog)\
**Post date:** [February 19, 2024, 2:08pm UTC](https://discourse.julialang.org/t/client-code-for-sse-server-sent-events-with-http-jl/110386/2 "2024-02-19T14:08:07Z")

</div>

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