using System.Collections.Generic;
using Microsoft.AspNetCore.WebUtilities;
using System.Net.Http.Json;
using System.Threading.Tasks;
public static async Task Main()
using (var httpClient = new HttpClient())
httpClient.BaseAddress = new Uri("https://datausa.io/");
var parameters = new Dictionary<string, string?>
{ "drilldowns", "Nation" },
{ "measures", "Population" }
string requestUrl = "api/dataxx";
requestUrl = QueryHelpers.AddQueryString(requestUrl, parameters);
var response = await httpClient.GetAsync(requestUrl);
if (!response.IsSuccessStatusCode)
Console.WriteLine($"{response.StatusCode}:{response.ReasonPhrase}");
var nationList = await response.Content.ReadFromJsonAsync<NationListDto>();
Console.WriteLine(JsonSerializer.Serialize(nationList));
public class NationListDto
public IEnumerable<NationDto> Data { get; init; } = [];
public string Nation { get; init; }
public int Year { get; init; }
public double Population { get; init; }