16

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.

ThCollignon
  • 976
  • 3
  • 14
  • 31
  • 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? – Danny Dainton Jan 02 '18 at 08:27
  • 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](https://stackoverflow.com/questions/44838290/rest-api-testing-how-to-get-response-using-google-chrome-developer-tools) 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. – ThCollignon Jan 02 '18 at 11:43
  • 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. – Danny Dainton Jan 02 '18 at 11:56

5 Answers5

8

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

EigenFool
  • 443
  • 1
  • 6
  • 14
7

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.

tim-montague
  • 16,217
  • 5
  • 62
  • 51
Samrat
  • 1,329
  • 12
  • 15
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

Capan
  • 686
  • 1
  • 14
  • 32
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/

Saad
  • 21
  • 1
  • 3
-1

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

nil96
  • 313
  • 1
  • 3
  • 12