meilisearch-java icon indicating copy to clipboard operation
meilisearch-java copied to clipboard

How to actually use an okhttp client

Open tropikoder opened this issue 3 years ago • 1 comments

what i need is to build a com.meilisearch.sdk.Client that uses OkHttp and jackson whenever it makes requests

I read the example on OkHttp in the documentation (and in the test source), but don't understand where to use the resulting serviceTemplate.

Thank you

Config config = new Config("http://localhost:7700", "masterKey");
HttpAsyncClient client = HttpAsyncClients.createDefault();
ApacheHttpClient client = new ApacheHttpClient(config, client);
private final JsonHandler jsonHandler = new JacksonJsonHandler(new ObjectMapper());
private final RequestFactory requestFactory = new BasicRequestFactory(jsonHandler);
private final GenericServiceTemplate serviceTemplate = new GenericServiceTemplate(client, jsonHandler, requestFactory);

private final ServiceTemplate serviceTemplate;
serviceTemplate.getProcessor().encode("your_data");
```


tropikoder avatar Jul 13 '22 15:07 tropikoder

Hi @tropikoder, Very sorry for the delay of answer. This part of the code was added a long time ago by a contributor to refactor the SDK; it was designed to create customizable handlers for each class such as :

    private final IndexHandler indexHandler = new IndexHandler(serviceTemplate, serviceTemplate.getRequestFactory());

But the final code was never merged so this part of the code is not fully functional. A big refactoring of the SDK is planned with only the use of the OkHttp client and will be available in a few weeks if all goes well. I'm not sure if my answer will help you a lot...

alallema avatar Jul 20 '22 14:07 alallema

Close due to merge of #425

alallema avatar Nov 09 '22 12:11 alallema