Can Postman or Chrome display REST streaming output?
Asked Answered
I

6

22

I have a REST server that is supposed to send plain text output as a stream, but when I perform the REST call with Postman or Chrome I get the whole output at once at the end of the process instead of getting a stream.

Here is my REST server, inspired from this article:

@GET
@Path("/stream-test")
@Produces(MediaType.TEXT_PLAIN)
public Response streamTest(){
  StreamingOutput stream = new StreamingOutput() {
    @Override
    public void write(OutputStream os) throws IOException, WebApplicationException {
      Writer writer = new BufferedWriter(new OutputStreamWriter(os));
      for (int i=1; i<=10; i++) {
        writer.write("output " + i + " \n");
        try {
          Thread.sleep(500);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
      writer.flush();
    }
  };
  return Response.ok(stream).build();
}

The output lines are all displayed at the same time. I would like to see an output each 500msec.

Is there something wrong with my implementation ?

Or are Postman and Chrome unable to display streaming outputs ?

Note: for technical reasons I still use Postman as a Chrome app.

Intitule answered 2/1, 2018 at 7:20 Comment(3)
Do you need to use Postman? I don’t think it will stream but if you’re using the chrome app, can you not use the dev tools console to test what you need?Laurentia
I use Postman mainly because I'm used to it and it's where I've saved my favorites API requests. DevTools doesn't seem to be the right tool for REST calls. Still I've tried and I can only see the output after the full execution like in Postman.Intitule
Ok, using the Dev Tools was just a suggest as you want to see a stream of data and Postman doesn't do that. You can get an AJAX code snippet from inside Postman and use this in the Dev Tools console or as a cURL request and see a stream of data in a terminal. I don't think Postman is going to give you want you're asking. The linked question is making standard requests rather than trying to stream data.Laurentia
S
13

Getting the CURL request from POSTMAN is not enough in case you are streaming. In my case, needed to append the option

--no-buffer

and worked fine

Sabrasabre answered 27/11, 2019 at 10:42 Comment(0)
E
10

cURL can

I had the same problem while using Server Send Events. I have resorted to using cURL on an Linux machine. I am sure Windows will have an alternative for cURL.

Edgell answered 2/7, 2018 at 15:53 Comment(4)
Ya true curl rocksBassett
can you share curl requestBullis
@Bullis - a simple curl followed by the URL will print the response as it streamsLiquidate
cURL also worked for me with HTTP/1 chunked transfer-encodingLiquidate
I
5

This post is quite recent; https://community.getpostman.com/t/stream-services-listener-how-to-test-in-postman/9714

Postman doesn't support streaming api's at the moment!

But as they've stated you can watch the issue on GitHub for updates ; https://github.com/postmanlabs/postman-app-support/issues/5040

Irreverent answered 22/12, 2019 at 11:33 Comment(1)
Postman still does not print responses as they streamLiquidate
C
2

Postman has just added support for consuming server-sent events. Note that this is unidirectional, from server to client.

Refer to: https://blog.postman.com/support-for-server-sent-events/

Cliftonclim answered 24/2, 2023 at 0:16 Comment(1)
this isn't for the responsesDoy
L
1

Currently SSE streaming doesn't work for JSON responses, but a new request has been added: https://github.com/postmanlabs/postman-app-support/issues/12713

Limicolous answered 13/3 at 21:14 Comment(0)
B
-1

curl -H 'X_BU_ID:anythingUwant' -H 'Content-Type: multipart/form-data' -v -F 'file=@filePath/abc.csv' http://localhost:35681/stream-test

Bullis answered 24/10, 2019 at 16:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.