Nathan
Nathan

Reputation: 8971

What is the difference between request() and submit() in Helidon's WebClientRequestBuilder?

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?

Upvotes: 0

Views: 367

Answers (2)

Romain Grecourt
Romain Grecourt

Reputation: 525

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.

Upvotes: 1

Nathan
Nathan

Reputation: 8971

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();
}

Upvotes: 0

Related Questions