Use the HTTP GET method to retrieve information from a database of weather records. Query https://jsonmock.hackerrank.com/api/weather/search?name={keyword} to search all records where name contains the keyword anywhere in its string value. The query result is paginated and can be further accessed by appending &page=num where num is the page number.
The query response from the API is a JSON with the following five fields:
page: the current pageper_page: the maximum number of results per pagetotal: the total number of records in the search resulttotal_pages: the total number of pages to query to get all the resultsdata: an array of JSON objects that contain weather records
The data field contains weather records with the following schema:
name: the name of the cityweather: temperature recordedstatus: an array of wind speed and humidity records
Filter records to include a given keyword in the name parameter. Return an array such that each element is a string of comma-separated values:
city_name, temperature, wind, humidity
For example, the JSON record is stored as:
Adelaide,15,8,61
Return the list sorted by city name.
Complete the function weatherStation(keyword).
Parameters:
string keyword: the string to search
Returns:
string[]: the weather data for each city
This problem asks you to consume a paginated weather API, collect every matching record across all pages, extract city name, temperature, wind speed, and humidity, then return the formatted strings sorted by city name. The main implementation details are looping through pages until all results are read and parsing the numeric values from the weather and status fields carefully.