Skip to content

Commit

Permalink
Move example WebClient code into a snippet (#8699)
Browse files Browse the repository at this point in the history
  • Loading branch information
barchetta authored Apr 24, 2024
1 parent 2ae8eb7 commit a279b86
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
20 changes: 11 additions & 9 deletions docs/src/main/asciidoc/se/webclient.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,19 @@ request methods. These methods will create a new instance of link:{webclient-jav
=== Customizing the Request
Configuration can be set for every request type before it is sent. Below are some examples of the optional parameters.
Configuration can be set for every request type before it is sent.
|===
|Parameter |Description
.Customizing a request
[source,java]
----
include::{sourcedir}/se/WebClientSnippets.java[tag=snippet_12, indent=0]
----
|`uri("http://example.com")` |Overrides baseUri from WebClient
|`path("/path")` |Adds path to the uri
|`queryParam("query", "parameter")` |Adds query parameter to the request
|`fragment("someFragment")` |Adds fragment to the request
|`headers(headers -> headers.addAccept(MediaType.APPLICATION_JSON))` |Adds header to the request
|===
<1> Overrides `baseUri` from WebClient
<2> Adds path to the uri
<3> Adds query parameter to the request
<4> Adds fragment to the request
<5> Adds header to the request
For more information about these optional parameters, check out link:{webclient-javadoc-base-url}.api/io/helidon/webclient/api/ClientRequestBase.html[ClientRequestBase] API, which is a parent class of link:{webclient-javadoc-base-url}.api/io/helidon/webclient/api/HttpClientRequest.html[HttpClientRequest].
Expand Down
16 changes: 16 additions & 0 deletions docs/src/main/java/io/helidon/docs/se/WebClientSnippets.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/
package io.helidon.docs.se;

import io.helidon.common.media.type.MediaTypes;
import io.helidon.config.Config;
import io.helidon.http.Method;
import io.helidon.http.media.MediaSupport;
import io.helidon.webclient.api.ClientResponseTyped;
import io.helidon.webclient.api.HttpClientRequest;
import io.helidon.webclient.api.HttpClientResponse;
import io.helidon.webclient.api.Proxy;
import io.helidon.webclient.api.WebClient;
Expand Down Expand Up @@ -160,4 +162,18 @@ void snippet_11() {
// end::snippet_11[]
}

void snippet_12() {
WebClient client = WebClient.builder()
.baseUri("http://localhost")
.build();
// tag::snippet_12[]
client.get()
.uri("http://example.com") // <1>
.path("/path") // <2>
.queryParam("query", "parameter") // <3>
.fragment("someFragment") // <4>
.headers(headers -> headers.accept(MediaTypes.APPLICATION_JSON)); // <5>
// end::snippet_12[]
}

}

0 comments on commit a279b86

Please sign in to comment.