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.
Postman doesn't support streaming api's at the moment! Show activity on this post.
In order to use the Postman Chrome app, you will first need to install Google Chrome browser. If you already have Chrome installed, head over to Postman's page on the Chrome Web store (https://chrome.google.com/webstore/detail/postman-rest-client-packa/fhbjgbiflinjbdggehcddcbncdddomop?hl=en), and click 'Add to Chrome'.
The difference between REST APIs and streaming APIs is: Streaming APIs updates are sent to the consumer when an event happens. REST APIs operate in a client-server architecture.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With