worldwide
Typed world country data.
import gleam/httpc
import gleam/json
import worldwide
import worldwide/region
pub fn main() {
let assert Ok(req) = worldwide.request()
let assert Ok(response) = httpc.send(req)
let assert Ok(countries) = json.parse(response.body, worldwide.decoder())
// Or let countries.dev do the filtering for you.
let assert Ok(europe_req) =
worldwide.filter(worldwide.ByRegion(region.Europe))
}
Types
Selects which countries.dev endpoint a request is built for.
pub type Filter {
ByName(String)
ByIso(String)
ByNumericCode(String)
ByIocCode(String)
ByRegion(region.Region)
BySubregion(subregion.Subregion)
ByCurrency(String)
ByLanguage(String)
ByCallingCode(Int)
ByTimeZone(String)
}
Constructors
-
ByName(String)Returns every country whose name contains the given value (case-insensitive).
-
ByIso(String)Returns a single country matching the given ISO 3166-1 alpha-2 or alpha-3 code (case-insensitive).
-
ByNumericCode(String)Returns the country matching the given ISO 3166-1 numeric code. Leading zeros are optional.
-
ByIocCode(String)Returns the country matching the given International Olympic Committee (IOC) country code.
-
ByRegion(region.Region)Returns every country in the given region (exact match, case-insensitive).
-
BySubregion(subregion.Subregion)Returns every country in the given subregion (exact match, case-insensitive).
-
ByCurrency(String)Returns every country that uses the given ISO 4217 currency code (case-insensitive).
-
ByLanguage(String)Returns every country that has the given language, matched by ISO 639-1 (
he) or ISO 639-2 (heb) code. -
ByCallingCode(Int)Returns every country that uses the given international calling code. This only filters by the country code, not the area code.
-
ByTimeZone(String)Returns every country that observes the given UTC timezone (exact match, case-insensitive, e.g. “UTC+02:00”)
Values
pub fn decoder() -> decode.Decoder(List(country.Country))
Decodes a country list response body into a list of Country.
pub fn filter(
filter: Filter,
) -> Result(request.Request(String), Nil)
Builds a request for the given filter, to be sent with an HTTP client
(gleam_httpc, gleam_fetch, etc…), then the response body decoded
with decoder().
pub fn request() -> Result(request.Request(String), Nil)
Builds a request for the complete list of countries.