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.

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? Commented Jan 2, 2018 at 8: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 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. Commented Jan 2, 2018 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. Commented Jan 2, 2018 at 11:56

6 Answers 6

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

0
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.

4
  • 2
    Ya true curl rocks Commented Nov 8, 2018 at 18:19
  • can you share curl request
    – nil96
    Commented Oct 24, 2019 at 15:37
  • @nil96 - a simple curl followed by the URL will print the response as it streams Commented Oct 4, 2022 at 20:46
  • cURL also worked for me with HTTP/1 chunked transfer-encoding Commented Oct 4, 2022 at 20:47
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

1
  • 2
    Postman still does not print responses as they stream Commented Oct 4, 2022 at 20:41
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/

1
  • 2
    this isn't for the responses
    – blockhead
    Commented Apr 2, 2023 at 9:45
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

-2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.