Apache HTTPClient Tutorial to invoke RESTFul service

Apache HttpClient to invoke a RESTful Web Service. This is a GET request, and in the next post will extend this to use an HTTP POST with basic authentication.

Step 1: Create a Maven project say “httpRestClient”. Just press enter for all the prompts.

Step 2: Import the above “httpRestClient” folder in the file system into eclipse. File –> Import –> “Existing Maven Projects” and then select the “httpRestClient” folder that was created by the “Step 1” from the file system.

Step 3: Add Apache HttpClient dependency to the pom.xml file

Step 4: Write the Java client class “RestClientTest” that invokes a RESTful web service.

Step 5: Before you run the above REST client, you need the REST service running. This was covered in HATEOAS RESTFul Service with Spring tutorial . Once the RESTFul service is running on a server, you can run the “RestClientTest” to hit the web service.

Output:


Java Interview FAQs

800+ Java Interview Q&As

Top