Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native support for Server-Sent Events and Streaming API endpoints #219

Open
sdeleuze opened this issue Apr 12, 2016 · 4 comments
Open

Native support for Server-Sent Events and Streaming API endpoints #219

sdeleuze opened this issue Apr 12, 2016 · 4 comments
Labels
type: enhancement Enhancement that adds a new feature

Comments

@sdeleuze
Copy link

sdeleuze commented Apr 12, 2016

Maybe Spring REST Docs could support natively Server-Sent Events endpoints, as supported in Spring Framework 4.2+ thanks to SseEmitter type, and global Streaming API support based on ResponseBodyEmitter type.

I am not sure yet about what that support would be, but for example Spring REST Docs could recognize SseEmitter return types, and generate a snippet with a curl command with text/event-streammedia type, handle the fact that some SSE endpoints never closes the connection (handle a timeout but not as an error?), and eventually provide Javascript code that would help people to use that endpoint in their application.

This issue is also intended to prepare support for Spring Web Reactive, which will provide first class support for streaming API via handler methods returning types like Flux<Foo> or Observable<Foo>. And unlike SseEmitter and ResponseBodyEmitter, these types will carry more type information within their Generic type.

@wilkinsona
Copy link
Member

@sdeleuze What's the current state of MockMvc for testing controller methods that return SseEmitter or ResponseBodyEmitter?

@andrashatvani
Copy link

Any news on this?

@wilkinsona
Copy link
Member

@andrashatvani Not really. We still think it's an idea worth exploring but haven't had the time to do so. If you have suggestions for how you'd like the support to look please let us know and perhaps we can kickstart something.

@wilkinsona wilkinsona added the type: enhancement Enhancement that adds a new feature label Mar 28, 2018
@rstoyanchev
Copy link
Contributor

Test streaming responses in Spring MVC has been possible through the WebTestClient since Spring Framework 5.0 by running with a live server. In 5.3 it became possible to run WebTestClient against a MockMvc instance as well. I've just improved the docs on that including a sample spring-projects/spring-framework#26687.

I think that Spring REST Docs can be used for streaming responses. For example something like this:

FluxExchangeResult<String> exchangeResult = this.webTestClient.get().uri("/")
		.exchange()
		.expectStatus().isOk()
		.returnResult(Person.class);

// Consume response
StepVerifier.create(result.getResponseBody())
		.expectNextCount(4)
		.thenCancel()
		.verify();

WebTestClientRestDocumentation.document("index").accept(exchangeResult);

In effect, let the response be tested and consumed first. Then it should be possible to access the response body content. Assuming this all works as expected, it should just be a matter of updating the reference docs with such guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Enhancement that adds a new feature
Projects
None yet
Development

No branches or pull requests

4 participants