mindee/mindee-api-java

(re) allow a user to provide their own HttpClient class

Closed this issue · 2 comments

In MindeeClientInit.java add a new method for initializing the client which:

  • follows builder pattern
  • allows setting apiKey, and an instance of HttpClient

When calling the parse method, use the provided HttpClient if set.

Internals could be described as follows:

Non je préfèrerais ne pas passer par les paramètres système
Au lieu de CloseableHttpClient httpClient = HttpClientBuilder.create().build() passer par HttpClients.custom() et assigner le proxy

@ianardee
The two options will look something like this from the users perspective.

private static void usingHttpClientBuilder() throws IOException {
    String apiKey = "my-api-key";
    String filePath = "/path/to/the/file.ext";
    
    HttpHost proxy = new HttpHost("localhost", 8090);
    DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
    HttpClientBuilder httpclientBuilder = HttpClients.custom()
        .setRoutePlanner(routePlanner);

    MindeeClient mindeeClient = MindeeClientInit.create(apiKey,httpclientBuilder);
    DocumentToParse docToParse = new DocumentToParse(new File(filePath));

    CustomEndpoint customEndpoint = new CustomEndpoint("my-endpoint","my-account");
    Document<CustomV1Inference> documentParsed =  mindeeClient.parse(docToParse,customEndpoint);
  }

  private static void usingMindeeApiImpl() throws IOException {
    String apiKey = "my-api-key";
    String filePath = "/path/to/the/file.ext";

    HttpHost proxy = new HttpHost("localhost", 8090);
    DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
    HttpClientBuilder httpclientBuilder = HttpClients.custom()
        .setRoutePlanner(routePlanner);

    MindeeSettings settings = new MindeeSettings(apiKey);
    MindeeHttpApi mindeeHttpApi = new MindeeHttpApi(settings,httpclientBuilder);

    MindeeClient mindeeClient = MindeeClientInit.create(mindeeHttpApi);
    DocumentToParse docToParse = new DocumentToParse(new File(filePath));

    CustomEndpoint customEndpoint = new CustomEndpoint("my-endpoint","my-account");
    Document<CustomV1Inference> documentParsed =  mindeeClient.parse(docToParse,customEndpoint);
  }

@vivekpaddy you're right, not very complicated at all.

Let's go with option 2 if it means having more flexibility.