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

[doc] Add example of using WS from main #6594

Merged
merged 2 commits into from
Sep 27, 2016

Conversation

wsargent
Copy link
Member

@wsargent wsargent commented Sep 26, 2016

Adds a description of using Play WS from a main method in the simple case, with no bells or whistles.

Adds documentation and examples for using WS standalone.
Adds notes to use Play's Timeout feature.

WSClient client = new AhcWSClient(config, materializer);
client.url("http://www.google.com").get().whenComplete((r, e) -> {
Optional.of(r).ifPresent(response -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use Optional.ofNullable here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...wow. It did not occur to me Optional.of was not the same as Option().

println(response.allHeaders)
}.andThen {
case _ =>
wsClient.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably do this in main. The way it's structured now makes it look like close should happen on every call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@wsargent wsargent merged commit e3b345b into playframework:master Sep 27, 2016
@wsargent wsargent deleted the doc-add-standalone-example branch September 27, 2016 03:22
@wsargent
Copy link
Member Author

wsargent commented Oct 8, 2016

Needs backport to 2.5.x

gmethvin pushed a commit that referenced this pull request Oct 8, 2016
* Add WSClient standalone and timeout docs

Adds documentation and examples for using WS standalone.
Adds notes to use Play's Timeout feature.

* Add Optional.ofNullable, clean up andThen
wsargent added a commit to wsargent/playframework that referenced this pull request Oct 18, 2016
* Add WSClient standalone and timeout docs

Adds documentation and examples for using WS standalone.
Adds notes to use Play's Timeout feature.

* Add Optional.ofNullable, clean up andThen
wsargent added a commit to wsargent/playframework that referenced this pull request Oct 25, 2016
* Add WSClient standalone and timeout docs

Adds documentation and examples for using WS standalone.
Adds notes to use Play's Timeout feature.

* Add Optional.ofNullable, clean up andThen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants