HttpClient needs to be instanced with a pre-configured base URI:
HttpClient<?> httpClient = Http1Client.builder().baseUri(uri).build();
This is different approach than jakarta.ws.rs.client.Client, where you are able to create the client without specifying the base URI:
Client client = ClientBuilder.newClient()
This forces you to create a new HttpClient for every different base URI, and this brings some usability issues. For example, imagine you have a class that makes HTTP requests to a bank URI. This class, lets say BankClient, knows the base URI of the bank. Problems:
If you want to pass an existing HttpClient in this class, you need to set the base URI in in advance (note the URI is known by BankClient and you are forcing the users of this class to know this URI).
Or in case you don't pass the existing HttpClient, and you let the BankClient to create it, there are other problems:
You cannot mock the client for testing
You cannot have multiple BankClient instances for the same HttpClient instance.
BankClient will need to care about closing the HttpClient.
BankClient will need to allow configuration of the HttpClient, like proxies, etc.
A solution could be that HttpClient is a wrapper of multiple HttpClient per URI.
Environment Details
Problem Description
HttpClient needs to be instanced with a pre-configured base URI:
HttpClient<?> httpClient = Http1Client.builder().baseUri(uri).build();
This is different approach than
jakarta.ws.rs.client.Client
, where you are able to create the client without specifying the base URI:Client client = ClientBuilder.newClient()
This forces you to create a new HttpClient for every different base URI, and this brings some usability issues. For example, imagine you have a class that makes HTTP requests to a bank URI. This class, lets say BankClient, knows the base URI of the bank. Problems:
A solution could be that HttpClient is a wrapper of multiple HttpClient per URI.
I noticed this issue while I was working on https://github.com/helidon-io/helidon/issues/8909 . There, I have to create a class that speaks with OpenAI.
Steps to reproduce