@GetMapping(path = "/cars", produces = "text/event-stream")
public Flux<Car> getCarStream() {
System.out.println("application/stream+json");
return this.repository.findCarsBy().log();
}
What's the difference between the above code and the following:
@GetMapping(path = "/cars", produces = "application/stream+json")
public Flux<Car> getCarStream() {
System.out.println("application/stream+json");
return this.repository.findCarsBy().log();
}
So far I've found the contradictory information: some say they both mean server-sent events and others that there is a difference.
TL;DR: that dzone article is wrong, and Rossen's talk is right.
text/event-stream
is the official media type for Server Sent Events (SSE); it will prefix data bits with a data:
prefix and you can also choose your prefix to change the meaning of that piece of data for the client. This media type is for browsers, as they support that using the EventSource
JavaScript API.
application/stream+json
is for server to server/http client (anything that's not a browser) communications. It won't prefix the data and will just use CRLF to split the pieces of data. Note that the Spring team is reconsidering that media type, because SPR-16742 (don't hesitate to comment there!).