0

Helidon's WebClientRequestBuilder has two similar APIs: request() and submit(). Both APIs return Single<WebClientResponse>.

request()'s Javadoc says...

Performs prepared request without expecting to receive any specific type. Response is not converted and returned CompletionStage is notified.

submit()'s Javadoc says...

Performs prepared request. When response is received, it is not converted to any other specific type and returned CompletionStage is notified.

What is the difference between the two APIs? Is it simply that request() adds a wildcard Accept header and submit() does not?

Nathan
  • 8,093
  • 8
  • 50
  • 76

2 Answers2

1

The request methods do not send any payload, they are short-hands that can be used to get the response entity as a specific type.

The submit methods can send payload and always return a response future.

// do a GET request and consume the response entity as a String

client.get()
      .submit()
      .thenAccept(response -> response.content()
                                      .as(String.class)
                                      .thenAccept(System.out::println));

client.get()
      .request(String.class)
      .thenAccept(System.out::println);

Both request() and submit() are effectively the same:

  • request() does not have a response entity type to work with and returns a response future instead.
  • submit() does not have payload to send and returns a response future like its other variants.
Romain Grecourt
  • 488
  • 2
  • 4
0

WebClientRequestBuilderImpl has the following source code. Both APIs do the same thing.

@Override
public Single<WebClientResponse> request() {
    return Contexts.runInContext(context, () -> invoke(Single.empty()));
}

@Override
public Single<WebClientResponse> submit() {
    return request();
}
Nathan
  • 8,093
  • 8
  • 50
  • 76