Jump to: navigation, search



HttpClient is the Jetty component that allows to make requests and interpret responses to HTTP servers.

This tutorial takes you through the steps necessary to use the HttpClient in the most effective way.


The HttpClient is by its nature asynchronous. This means that the code that sends the request does not wait for the response to arrive before continuing. Instead, the request is sent concurrently to your code, and the response is interpreted also concurrently with your code.

The HttpClient API offers you callbacks to interact with the request-response lifecycle. These callbacks will be called by the HttpClient implementation to allow further actions to be performed during each request-response event.

A request-response unit is called exchange, and represent the exchange of information with the HTTP server.

There are two main classes in the HttpClient API:

  • org.eclipse.jetty.client.HttpClient, which manages the thread pooling, the proxy setting, the authentication settings, the connector type (blocking or non-blocking), the SSL settings and the timeouts. HttpClient manages the configuration that does not depend on a particular exchange.
  • org.eclipse.jetty.client.HttpExchange, which is the base class that you normally have to subclass that represent the exchange with the HTTP server, and manages HTTP method, the request URI, HTTP headers, request content, HTTP response code, HTTP response headers and response content.