Creating a standard Java HTTP client
An HTTP client is one of the easiest clients to create. It's very handy because it allows for the calling, not only of the internal methods as the native protocol does, but also of third-party calls implemented in plugins that can be only called via HTTP.
Getting ready
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
A Maven tool, or an IDE that natively supports it for Java programming such as Eclipse or IntelliJ IDEA, must be installed.
The code for this recipe is in the chapter_14/http_java_client
directory.
How to do it...
For creating a HTTP client, we will perform the following steps:
For these examples, we have chosen the Apache HttpComponents that is one of the most widely used libraries for executing HTTP calls. This library is available in the main Maven repository
search.maven.org
. To enable the compilation in your Mavenpom.xml
project...