RestcountriesEx is a Elixir wrapper for the Rest Countries API.
NOTE This package is not yet available in Hex
If available in Hex, the package can be installed
by adding restcountries_ex
to your list of dependencies in mix.exs
:
def deps do
[
{:restcountries_ex, "~> 0.1.0"}
]
end
The package maps all endpoints, except the https://restcountries.eu/rest/v2/alpha/code
. That endpoint seems redundant since there is also an endpoint for searching by a list of codes.
- Get all countries. By default, this returns all the fields of each country item. You can pass a list of wanted fields. See the example below.
iex> RestcountriesEx.all()
{:ok, [%{}]
iex> RestcountriesEx.all(["name"])
{:ok, [%{"name": name}]}
- Find a country by name. Accepts a binary/string and an optional boolean for
full_text
. Thefull_text
option will pass thefullText=true
query params to the endpoint, which will perform a stricter search.
iex> RestcountriesEx.find_by_name("united") # should return two countries United States of America and United States Minor Outlying Isalands
{:ok, [%{}, ...]}
iex> RestcountriesEx.find_by_name("united", true) # should return nothing
iex> RestcountriesEx.find_by_name('united states of america", true), # should return
{:ok, [%{}, ...]}
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/restcountries_ex.