diff --git a/rx-java3/src/main/asciidoc/vertx-web-client/java/override/rxjava3.adoc b/rx-java3/src/main/asciidoc/vertx-web-client/java/override/rxjava3.adoc index 136b3fce..f71b0bca 100644 --- a/rx-java3/src/main/asciidoc/vertx-web-client/java/override/rxjava3.adoc +++ b/rx-java3/src/main/asciidoc/vertx-web-client/java/override/rxjava3.adoc @@ -16,15 +16,14 @@ The obtained `Single` can be composed and chained naturally with the RxJava API {@link examples.RxWebClientExamples#flatMap(io.vertx.rxjava3.ext.web.client.WebClient)} ---- -The same APIs is available +The same APIs are available: [source,java] ---- {@link examples.RxWebClientExamples#moreComplex(io.vertx.rxjava3.ext.web.client.WebClient)} ---- -The {@link io.vertx.rxjava3.ext.web.client.HttpRequest#rxSendStream(io.reactivex.rxjava3.core.Flowable)} shall -be preferred for sending bodies `Flowable`. +The {@link io.vertx.rxjava3.ext.web.client.HttpRequest#rxSendStream(io.reactivex.rxjava3.core.Flowable)} shall be preferred for sending bodies `Flowable`. [source,java] ---- @@ -32,3 +31,14 @@ be preferred for sending bodies `Flowable`. ---- Upon subscription, the `body` will be subscribed and its content used for the request. + +=== HTTP Response Expectations + +Interacting with an HTTP backend often involves verifying HTTP response codes and/or content types. + +To streamline the process of verification, use the {@link io.vertx.rxjava3.core.http.HttpResponseExpectation} methods: + +[source,java] +---- +{@link examples.RxWebClientExamples#httpResponseExpectations(io.vertx.rxjava3.ext.web.client.WebClient)} +---- diff --git a/rx-java3/src/main/java/examples/RxWebClientExamples.java b/rx-java3/src/main/java/examples/RxWebClientExamples.java index 8f8a4059..52b3bda4 100644 --- a/rx-java3/src/main/java/examples/RxWebClientExamples.java +++ b/rx-java3/src/main/java/examples/RxWebClientExamples.java @@ -2,9 +2,10 @@ import io.reactivex.rxjava3.core.Flowable; import io.reactivex.rxjava3.core.Single; +import io.vertx.core.buffer.Buffer; import io.vertx.core.json.JsonObject; import io.vertx.docgen.Source; -import io.vertx.core.buffer.Buffer; +import io.vertx.rxjava3.core.http.HttpResponseExpectation; import io.vertx.rxjava3.ext.web.client.HttpResponse; import io.vertx.rxjava3.ext.web.client.WebClient; import io.vertx.rxjava3.ext.web.codec.BodyCodec; @@ -73,4 +74,14 @@ public void sendFlowable(WebClient client) { System.out.println(resp.body()); }); } + + public void httpResponseExpectations(WebClient client) { + Single> single = client + .get(8080, "myserver.mycompany.com", "/some-uri") + .rxSend() + // Transforms the single into a failed single if the HTTP response is not successful + .compose(HttpResponseExpectation.status(200)) + // Transforms the single into a failed single if the HTTP response content is not JSON + .compose(HttpResponseExpectation.contentType("application/json")); + } }