Mastering HTTP GET Interface Testing with FunTester: A Hands‑On Java Example

This article walks through building and executing an HTTP GET request to Tencent Weather's API using the FunTester framework in Java, showing how to assemble parameters, send the request, parse the JSON response, and verify key data points.

FunTester
FunTester
FunTester
Mastering HTTP GET Interface Testing with FunTester: A Hands‑On Java Example

Overview

This example demonstrates how to perform HTTP GET interface testing by calling the public Tencent Weather API. It shows how to build a request object, encode query parameters, send the request, and parse the JSON response to verify the returned data and HTTP status.

Repository

Source code is hosted at the following Gitee repository (plain URL for reference): https://gitee.com/fanapi/tester

Implementation Details

The test is written in Java and extends FanLibrary, a utility class that wraps Apache HttpClient and FastJSON handling. The main steps are:

Define the endpoint :

String url = "https://wis.qq.com/weather/common";

Prepare query parameters as a JSONObject (FastJSON). The parameters required by the API are:

params.put("source", "pc");
params.put("province", "北京市");
params.put("city", "北京市");
params.put("county", "西城区");
params.put("weather_type", "observe|forecast_1h|forecast_24h|index|alarm|limit|tips|rise");

Create the HTTP GET object using the helper method getHttpGet(url, params). This method URL‑encodes the parameters and attaches them to the request URI.

Execute the request with getHttpResponse(httpGet). The method sends the request, reads the response body, and converts it into a JSONObject.

Output the result using output(). The full JSON payload and the value of the status field are printed.

Optional detailed parsing (commented out in the source): retrieve the forecast_24h object, iterate over its keys, and print each hour’s maximum temperature and timestamp.

Full Source Code

package com.fun;

import com.alibaba.fastjson.JSONObject;
import com.fun.frame.httpclient.FanLibrary;
import org.apache.http.client.methods.HttpGet;

public class WeacherTest extends FanLibrary {
    public static void main(String[] args) {
        String url = "https://wis.qq.com/weather/common";
        JSONObject params = new JSONObject();
        params.put("source", "pc");
        params.put("province", "北京市");
        params.put("city", "北京市");
        params.put("county", "西城区");
        params.put("weather_type", "observe|forecast_1h|forecast_24h|index|alarm|limit|tips|rise");

        // Build GET request with encoded query string
        HttpGet httpGet = getHttpGet(url, params);

        // Execute request and obtain JSON response
        JSONObject response = getHttpResponse(httpGet);

        // Print the complete response and status code
        output(response);
        output("Response status:" + response.getInteger("status"));

        // ---- Optional detailed forecast parsing (uncomment to use) ----
        // output("Message:" + response.getString("message"));
        // JSONObject forecast = response.getJSONObject("data").getJSONObject("forecast_24h");
        // for (String hour : forecast.keySet()) {
        //     int maxTemp = forecast.getJSONObject(hour).getIntValue("max_degree");
        //     String time = forecast.getJSONObject(hour).getString("time");
        //     output(time + " max temperature: " + maxTemp + "°C");
        // }
        // ------------------------------------------------------------

        testOver();
    }
}

Key Points

All query parameters are sent as part of the URL; no request body is needed for a GET request.

The helper methods in FanLibrary abstract away connection management, character encoding, and JSON conversion.

FastJSON ( com.alibaba.fastjson.JSONObject) provides convenient put, getInteger, and getJSONObject operations for building and reading JSON structures.

Commented code shows how to drill into nested JSON objects (e.g., hourly forecast) without affecting the basic test flow.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaGiteeAPI testingHTTP testingFunTesterGET request
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.