| 1 | # EDC Http Client |
| 2 | |
| 3 | ## Decision |
| 4 | |
| 5 | An `EdcHttpClient` will be introduced to wrap `OkHttpClient` and `Failsafe` functionalities. |
| 6 | |
| 7 | ## Rationale |
| 8 | |
| 9 | At the moment, everytime the `Failsafe` retry mechanism is needed there's the need to inject the relative `RetryPolicy` |
| 10 | service and explicitly use it everytime we need to call an http endpoint. |
| 11 | Retry mechanism is something we definitely want to have out-of-the-box as in fact it is something we expect to see used |
| 12 | in every http call. |
| 13 | |
| 14 | ## Approach |
| 15 | |
| 16 | An `EdcHttpClient` interface will be introduced in a `http-spi` module: |
| 17 | ```java |
| 18 | public 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 | |
| 29 | The implementation will use `okhttp` and `failsafe-okttp` to provide retry mechanism using the registered `RetryPolicy`. |
| 30 | The implementation service will be provided by the `CoreDefaultServicesExtension`. |
| 31 | |
| 32 | This service would be used instead of `OkHttpClient` and `RetryPolicy`, and in the future it could provide other features |
| 33 | or, also, provide a more okhttp-agnostic interface. |
| 34 | |
| 35 | The `withDns` method is necessary for the `WebDidExtension`. |