if we only keep the list of countries and cities in memory, we can query it on demand and no page refresh needed. this approach would also work for the cli menu. i guess the program flow for point 1 is:
1) generate a list of countries and cities, with ids -> user selects their preference
Code:
curl -s -m 5 "https://api.nordvpn.com/v1/servers/countries?limit=16384" | jq --raw-output '.[] | . as $parent | .cities[] | [$parent.name, $parent.id, .name, .id] | "[\"\(.[0])\",\"\(.[1])\",\"\(.[2])\",\"\(.[3])\"]"'
2) use selected country as a filter for recommendation api, get top 5 and sort by load (querying all servers and filtering in jq is VERY SLOW on the router (tested on my 86U)
Code:
curl --silent "https://api.nordvpn.com/v1/servers/recommendations?filters\[country_id\]=227&limit=5" | jq --raw-output ' .[] | select(.locations[].country.city.id="2989907")' | jq --raw-output --slurp ' sort_by(.load) | limit(5;.[]) | [
.hostname, .load] | "\(.[0]): \(.[1])"'
3) 5s (is that sufficient) ping test to each of the 5 servers,
4) sort servers by avg ping in ascending order
5) configure VPN to use lowest average ping server
does that look right?