Elffuss BraidHub

kikocis/EDC public

main · 1.2 KiBRenderedRawPermalink
1# EDC Http Client
2
3## Decision
4
5An `EdcHttpClient` will be introduced to wrap `OkHttpClient` and `Failsafe` functionalities.
6
7## Rationale
8
9At the moment, everytime the `Failsafe` retry mechanism is needed there's the need to inject the relative `RetryPolicy`
10service and explicitly use it everytime we need to call an http endpoint.
11Retry mechanism is something we definitely want to have out-of-the-box as in fact it is something we expect to see used
12in every http call.
13
14## Approach
15
16An `EdcHttpClient` interface will be introduced in a `http-spi` module:
17```java
18public interface EdcHttpClient {
19
20 Response execute(Request request) throws IOException;
21
22 <T> CompletableFuture<T> executeAsync(Request request, Function<Response, T> mappingFunction);
23
24 EdcHttpClient withDns(String dnsServer);
25
26}
27```
28
29The implementation will use `okhttp` and `failsafe-okttp` to provide retry mechanism using the registered `RetryPolicy`.
30The implementation service will be provided by the `CoreDefaultServicesExtension`.
31
32This service would be used instead of `OkHttpClient` and `RetryPolicy`, and in the future it could provide other features
33or, also, provide a more okhttp-agnostic interface.
34
35The `withDns` method is necessary for the `WebDidExtension`.