Interface HttpClient

All Known Subinterfaces:
HttpClientContext

public interface HttpClient
The HTTP client context that we use to build and process requests.


   HttpClient client = HttpClient.builder()
       .baseUrl("http://localhost:8080")
       .bodyAdapter(new JacksonBodyAdapter())
       .build();

  HelloDto dto = client.request()
       .path("hello")
       .queryParam("name", "Rob")
       .queryParam("say", "Whats up")
       .GET()
       .bean(HelloDto.class);

 
  • Method Details

    • builder

      static HttpClient.Builder builder()
      Return the builder to config and build the client context.
      
      
         HttpClient client = HttpClient.builder()
             .baseUrl("http://localhost:8080")
             .bodyAdapter(new JacksonBodyAdapter())
             .build();
      
        HttpResponse<String> res = client.request()
             .path("hello")
             .GET().asString();
      
       
    • create

      <T> T create(Class<T> clientInterface)
      Return the http client API implementation.
      Type Parameters:
      T - The service type.
      Parameters:
      clientInterface - A @Client interface with annotated API methods.
      Returns:
      The http client API implementation.
    • request

      Create a new request.
    • converters

      @Deprecated default BodyAdapter converters()
      Deprecated.
      Deprecated - migrate to bodyAdapter().

      Return the body adapter used by the client context.

      This is the body adapter used to convert request and response bodies to java types. For example using Jackson with JSON payloads.

    • bodyAdapter

      BodyAdapter bodyAdapter()
      Return the BodyAdapter that this client is using.
    • metrics

      Return the current aggregate metrics.

      These metrics are collected for all requests sent via this context.

    • metrics

      HttpClient.Metrics metrics(boolean reset)
      Return the current metrics with the option of resetting the underlying counters.

      These metrics are collected for all requests sent via this context.