Execute get request with Apache Components

This example will show how to make a get request using Apache HttpComponents httpclient. In the event you are using Commons HttpClient, you will want to upgrade as it is no longer being developed. This approach is pretty low level and most frameworks wrap this code to make deserializing responses to java object simpler.

SparkFun allows you to create a dynamic feed or stream of data. Exploring the public feed we will make a request to Wimp Weather Station returning a response content type of JSON.

public void make_request_http_client() throws ClientProtocolException,
        IOException {

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet(
    CloseableHttpResponse response = httpclient.execute(httpget);
    try {
        HttpEntity entity = response.getEntity();

        if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) {
            String responseValue = EntityUtils.toString(entity);
        } else {
            // log error
    } finally {




        "long":"Boulder, CO, United States",
        "country":"United States",
      "title":"Wimp Weather Station",
      "description":"Weather station on top my roof. Read the full tutorial here: https://learn.sparkfun.com/tutorials/weather-station-wirelessly-connected-to-wunderground",