title: Ktor response streaming
body: <p>I am trying to call a twitter endpoint that gives you a constant streams of json results back to the client</p>
  <p><a href="https://documenter.getpostman.com/view/9956214/T1LMiT5U#977c147d-0462-4553-adfa-d7a1fe59c3ec" rel="nofollow noreferrer">https://documenter.getpostman.com/view/9956214/T1LMiT5U#977c147d-0462-4553-adfa-d7a1fe59c3ec</a></p>
  <p>I try to make a call to the endpoint like this</p>
  <pre><code>        val url = &quot;https://api.twitter.com/2/tweets/search/stream&quot;
          _streamChannel = _client.get&lt;ByteReadChannel&gt;(token, url) //Stops here
  
          val byteBufferSize = 1024
          val byteBuffer = ByteArray(byteBufferSize)
  
          _streamChannel?.let {
              while (_streamChannel!!.availableForRead &gt; 0) {
                  _streamChannel!!.readAvailable(byteBuffer, 0, byteBufferSize)
                  val s = String(byteBuffer)
                  parseStreamResponseString(s).forEach {
                      emit(Response.Success(it))
                  }
              }
          }
  </code></pre>
  <p>my <code>client.get</code> code is this</p>
  <pre><code>suspend inline fun &lt;reified T&gt; get(authKey: String, url: String): T? {
      val response = _client.get&lt;HttpResponse&gt;(url) {
          header(&quot;Authorization&quot;, &quot;Bearer $authKey&quot;)
      }
  
      when (response.status.value) {
          in 300..399 -&gt; throw RedirectResponseException(response)
          in 400..499 -&gt; throw ClientRequestException(response)
          in 500..599 -&gt; throw ServerResponseException(response)
      }
  
      if (response.status.value &gt;= 600) {
          throw ResponseException(response)
      }
  
      return response.receive&lt;T&gt;()
  }
  </code></pre>
  <p>When I make the request it just sits there in what I am assuming is waiting for the full response to be returned before giving it to me.</p>
  <p><strong>Edit</strong></p>
  <p>I also tried using <a href="https://ktor.io/docs/streaming.html" rel="nofollow noreferrer">scoped streaming</a> but it just sits at the line <code>readAvailable</code> I know there are messages coming through because when I run the request via <code>cURL</code> I am constantly getting data</p>
  <pre><code>    _client.get&lt;HttpStatement&gt; {
          header(&quot;Authorization&quot;, &quot;Bearer $authKey&quot;)
          url(urlString)
          contentType(ContentType.Application.Json)
          method = HttpMethod.Get
      }.execute {
          val streamChannel = it.receive&lt;ByteReadChannel&gt;()
          val byteBufferSize = 1024
          val byteBuffer = ByteArray(byteBufferSize)
          streamChannel.readAvailable(byteBuffer, 0, byteBufferSize) // Stops here
          val s = String(byteBuffer)
      }
  </code></pre>
  <p>How do I process a constant stream of json data using Ktor?</p>