I've created a microservice that returns a response in form of a stream using StreamingResponseBody
class. I want to consume this response in AJAX call using RxJS Observables in my Angular 4 application. Here is my controller:
@RestController
public class MyController {
@RequestMapping(value = "/api/oneToHundred", method = RequestMethod.GET)
public StreamingResponseBody oneToHundred() {
return new StreamingResponseBody() {
@Override
public void writeTo(OutputStream out) throws IOException {
for (int i=1;i<=100;i++) {
out.write((i + "\n").getBytes());
out.flush();
}
}
};
}
}
Needless to say that there will be partial results before the request is entirely completed. I want to update the UI as soon as I'm getting a partial result, say display each partial result in as a list item on my HTML page like follows:
- 1
- 2...
after next set of partial response
- 1
- 2
- 3
- 4...
after next set of partial response
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9......
upto
- ...
- 98
- 99
- 100
Is it possible?