mirror of
https://gitlab.com/restcountries/restcountries.git
synced 2026-03-31 15:07:46 +01:00
adding V3 with new country structure
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEA6QClRCIjQN6SlEVeWErrJdlzURT0xX5KxJD0SswcHDQDCxVE
|
||||
0hp/z+kQjr0wT0iGf4z6d+OIJiDO+/lQ76KxPq5vj0J86AuZMOzKPbWF+7pihN0v
|
||||
JNB7KkqEsI1fIppYlaA3xD0o5Q+VAvS/92Y5/z6jLwRG8eNp7mcO67U7QJO9PIS5
|
||||
TtHYFyTzCwSg7JHsr2I64yQye1TB5wBnhS4zBqBDL2VZz4KnEa1fnMtGEhLNGEM4
|
||||
nzOgfGIwamDbICedcGQ0yBuKb8908k8sCgjFWxxcRsLG1aak/NU3ecKXln7vV2zn
|
||||
/QUxLub2V27J9DXILTza07DUgeCB8kcNqqm1RwIDAQABAoIBAEyAp8K9KrIL4jjI
|
||||
pfd7ccXVpeVDajLGCqqLpYpBhiFEepNTAmuxw7FyJruXJpuBhpeupDZlALj0IMHe
|
||||
1FI6KtQX1g1FmVlfJYdI2AZ26W0Df4F8VhRSV35FRVfqswfbgaZvGqBWLG05NoXn
|
||||
8ne6muRRnqa7UsftEUTzlZSSxsemmhFlJd03MeS/REtz+ELGZT1U/0SsJB8sHp8b
|
||||
U6xk3yKKQgi3nQooovrdHsmDvP0NDaUwrMYUvvQfuSUktUrSs8wMFiDU1c2d5Iwy
|
||||
oqjIMoDHqOEI+q0MqR8tYKSxyU2j+/r0wjxiZcoDb5ZZCBqVaUUMSTqwFAlPwps4
|
||||
zdektvECgYEA+7ijFqiyNCPRqYmIvBoZ1rmOdzJ6AtLdelaarYpcwiuDmY2OOKjH
|
||||
4xYztWjLQMZPc6b9iYuP2nOAMGZYXifsxRLcOOAd2C8KI9fMYjE9+ubL38SNo5V1
|
||||
/3AXsvtkdgbn/B1LHigXcpv/mvMuvv725WD9K+q+JeyOS5OUwJGJeqsCgYEA7PaN
|
||||
3YjqbHy+8Vcgn5KZHJofR4+AwFV+RwangfjQHS3mDGnVWQvShbILsWe42MSWtBhH
|
||||
WZNlRzPAaV2MTUq/ZPSTvHXdBQDW/msQO9naSgzVDAall3v38YaquO9QF7eMXcP8
|
||||
XrihSsmFMASE9/+sVxj9Y8fVvWPzcRT3Pl1D79UCgYBVAcFxwX6MxRvk2SFoBJh9
|
||||
PySxdEZn9bX9vol12agBmphSns9MqxL1yWWk+cLKGS5zrA0rCgqGh0LfFXD6Oxlm
|
||||
ZDwiqOzrONd/yzymXGLF/HMVGleKysqSfNRECUmf4i0toubfRELG3Y+wUDeVIJ1Y
|
||||
USyuTBPy0rQrKaeucHexCQKBgQDbCVC7PYsLuwe5CEOEnTrgoGpXeIOXxa8TMkh2
|
||||
MKsWvc2PHejzBaWUpa5/TxQjcxym3mZdm4ybk2/BNZKyA20FgbpqEzy5GjyhMg/w
|
||||
cwB/QHtSQXahnxribAu1JKkRMz4Rkk7es6WL/tkZOKQ8pV4FqHjY2ehtx01I8wtT
|
||||
31wj/QKBgBCQq6nlDZ7tHs+Pdjmb8h9m0f5MuuThJbcEll/fPm/TVYb5Qem/mUcs
|
||||
fKY/SonBSYiu62rmZWHEj1FxE/wGCgl+8AG4LblBdOBaLzc+iv3qBK+3obNI8bJc
|
||||
8Bkuh93Fxurlr13pDpqM4NKQREURMTJ0GmyDLAFEjFIFQBfo1P5O
|
||||
-----END RSA PRIVATE KEY-----
|
||||
@@ -0,0 +1 @@
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDpAKVEIiNA3pKURV5YSusl2XNRFPTFfkrEkPRKzBwcNAMLFUTSGn/P6RCOvTBPSIZ/jPp344gmIM77+VDvorE+rm+PQnzoC5kw7Mo9tYX7umKE3S8k0HsqSoSwjV8imliVoDfEPSjlD5UC9L/3Zjn/PqMvBEbx42nuZw7rtTtAk708hLlO0dgXJPMLBKDskeyvYjrjJDJ7VMHnAGeFLjMGoEMvZVnPgqcRrV+cy0YSEs0YQzifM6B8YjBqYNsgJ51wZDTIG4pvz3TyTywKCMVbHFxGwsbVpqT81Td5wpeWfu9XbOf9BTEu5vZXbsn0NcgtPNrTsNSB4IHyRw2qqbVH alejandro@DESKTOP-6U7UA06
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
mvn clean install
|
||||
docker build -t registry.gitlab.com/amatos/rest-countries:master .
|
||||
docker push registry.gitlab.com/amatos/rest-countries:master
|
||||
ssh root@restcountries.com "./restart"
|
||||
@@ -206,12 +206,12 @@ public class CountryController {
|
||||
}
|
||||
|
||||
private String getCountriesJson(List<Country> countries, List<String> fields) {
|
||||
Gson gson = new Gson();
|
||||
JsonParser parser = new JsonParser();
|
||||
var gson = new Gson();
|
||||
var parser = new JsonParser();
|
||||
JsonArray jsonArray = parser.parse(gson.toJson(countries)).getAsJsonArray();
|
||||
JsonArray resultArray = new JsonArray();
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JsonObject jsonObject = (JsonObject) jsonArray.get(i);
|
||||
var resultArray = new JsonArray();
|
||||
for (var i = 0; i < jsonArray.size(); i++) {
|
||||
var jsonObject = (JsonObject) jsonArray.get(i);
|
||||
|
||||
List<String> excludedFields = getExcludedFields(fields);
|
||||
for (String excludedField : excludedFields) {
|
||||
@@ -229,7 +229,7 @@ public class CountryController {
|
||||
}
|
||||
|
||||
private Object getResponse(Response.Status status) {
|
||||
Gson gson = new Gson();
|
||||
var gson = new Gson();
|
||||
return Response
|
||||
.status(status)
|
||||
.entity(gson.toJson(new ResponseEntity(status.getStatusCode(),
|
||||
@@ -245,8 +245,8 @@ public class CountryController {
|
||||
}
|
||||
|
||||
private String getCountryJson(Country country, List<String> fields) {
|
||||
Gson gson = new Gson();
|
||||
JsonParser parser = new JsonParser();
|
||||
var gson = new Gson();
|
||||
var parser = new JsonParser();
|
||||
JsonObject jsonObject = parser.parse(gson.toJson(country)).getAsJsonObject();
|
||||
|
||||
List<String> excludedFields = getExcludedFields(fields);
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
package dev.amatos.restcountries.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import dev.amatos.restcountries.domain.ICountryRestSymbols;
|
||||
import dev.amatos.restcountries.domain.ResponseEntity;
|
||||
import dev.amatos.restcountries.service.v3.CountryService;
|
||||
import dev.amatos.restcountries.v3.domain.Country;
|
||||
import io.micronaut.http.MediaType;
|
||||
import io.micronaut.http.annotation.Controller;
|
||||
import io.micronaut.http.annotation.Get;
|
||||
import io.micronaut.http.annotation.PathVariable;
|
||||
import io.micronaut.http.annotation.QueryValue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Controller("v3/")
|
||||
public class CountryControllerV3 {
|
||||
|
||||
@Get(uri = "all", produces = MediaType.APPLICATION_JSON)
|
||||
public Object getAllCountries(@QueryValue("fields") Optional<String> fields) {
|
||||
List<Country> countries = CountryService.getInstance().getAll();
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
|
||||
private Object checkFieldsAndParseCountries(Optional<String> fields, List<Country> countries) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountries(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountries(countries, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("alpha/{alphacode}")
|
||||
public Object getByAlpha(@PathVariable("alphacode") String alpha,
|
||||
@QueryValue("fields") Optional<String> fields) {
|
||||
if (alpha.contains("codes")) {
|
||||
alpha = alpha.replace("codes=", "");
|
||||
}
|
||||
if (isEmpty(alpha) || alpha.length() < 2 || alpha.length() > 3) {
|
||||
return getResponse(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
var country = CountryService.getInstance().getByAlpha(alpha);
|
||||
if (country != null) {
|
||||
return checkFieldsAndParseCountry(country, fields);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
}
|
||||
|
||||
private Object checkFieldsAndParseCountry(Country country, Optional<String> fields) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountry(country, fields.get());
|
||||
} else {
|
||||
return parsedCountry(country, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("alpha/")
|
||||
public Object getByAlphaList(@QueryParam("codes") String codes,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(codes) || codes.length() < 2 || (codes.length() > 3 && !codes.contains(","))) {
|
||||
return getResponse(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
List<Country> countries = CountryService.getInstance().getByCodeList(codes);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("currency/{currency}")
|
||||
public Object getByCurrency(@PathVariable("currency") String currency,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(currency)) {
|
||||
return getResponse(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
List<Country> countries = CountryService.getInstance().getByCurrency(currency);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("name/{name}")
|
||||
public Object getByName(@PathVariable("name") String name,
|
||||
@QueryParam("fullText") Optional<Boolean> fullText,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryService.getInstance()
|
||||
.getByName(name, fullText.orElse(false));
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("capital/{capital}")
|
||||
public Object getByCapital(@PathVariable("capital") String capital,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryService.getInstance().getByCapital(capital);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Get("region/{region}")
|
||||
public Object getByContinent(@PathVariable("region") String region,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryService.getInstance().getByRegion(region);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("subregion/{subregion}")
|
||||
public Object getBySubRegion(@PathVariable("subregion") String subregion,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryService.getInstance().getBySubregion(subregion);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("lang/{lang}")
|
||||
public Object getByLanguage(@PathVariable("lang") String language,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryService.getInstance().getByLanguage(language);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("demonym/{demonym}")
|
||||
public Object getByDemonym(@PathVariable("demonym") String demonym,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryService.getInstance().getByDemonym(demonym);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("translation/{translation}")
|
||||
public Object getByTranslation(@PathVariable("translation") String translation,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryService.getInstance().getByTranslation(translation);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private Object parsedCountries(List<Country> countries, String excludedFields) {
|
||||
if (excludedFields == null || excludedFields.isEmpty()) {
|
||||
return countries;
|
||||
} else {
|
||||
return getCountriesJson(countries,
|
||||
Arrays.asList(excludedFields.split(ICountryRestSymbols.COLON)));
|
||||
}
|
||||
}
|
||||
|
||||
private String getCountriesJson(List<Country> countries, List<String> fields) {
|
||||
var gson = new Gson();
|
||||
var parser = new JsonParser();
|
||||
var jsonArray = parser.parse(gson.toJson(countries)).getAsJsonArray();
|
||||
var resultArray = new JsonArray();
|
||||
for (var i = 0; i < jsonArray.size(); i++) {
|
||||
var jsonObject = (JsonObject) jsonArray.get(i);
|
||||
|
||||
List<String> excludedFields = getExcludedFields(fields);
|
||||
for (String excludedField : excludedFields) {
|
||||
jsonObject.remove(excludedField);
|
||||
}
|
||||
resultArray.add(jsonObject);
|
||||
}
|
||||
return resultArray.toString();
|
||||
}
|
||||
|
||||
private List<String> getExcludedFields(List<String> fields) {
|
||||
List<String> excludedFields = new ArrayList<>(Arrays.asList(COUNTRY_FIELDS));
|
||||
excludedFields.removeAll(fields);
|
||||
return excludedFields;
|
||||
}
|
||||
|
||||
private Object getResponse(Response.Status status) {
|
||||
var gson = new Gson();
|
||||
return Response
|
||||
.status(status)
|
||||
.entity(gson.toJson(new ResponseEntity(status.getStatusCode(),
|
||||
status.getReasonPhrase()))).build().getEntity();
|
||||
}
|
||||
|
||||
private Object parsedCountry(Country country, String fields) {
|
||||
if (fields == null || fields.isEmpty()) {
|
||||
return country;
|
||||
} else {
|
||||
return getCountryJson(country, Arrays.asList(fields.split(ICountryRestSymbols.COLON)));
|
||||
}
|
||||
}
|
||||
|
||||
private String getCountryJson(Country country, List<String> fields) {
|
||||
var gson = new Gson();
|
||||
var parser = new JsonParser();
|
||||
var jsonObject = parser.parse(gson.toJson(country)).getAsJsonObject();
|
||||
|
||||
List<String> excludedFields = getExcludedFields(fields);
|
||||
for (String field : excludedFields) {
|
||||
jsonObject.remove(field);
|
||||
}
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
private static final String[] COUNTRY_FIELDS = new String[]{
|
||||
"name",
|
||||
"tld",
|
||||
"cca2",
|
||||
"ccn3",
|
||||
"cca3",
|
||||
"cioc",
|
||||
"independent",
|
||||
"status",
|
||||
"unMember",
|
||||
"currencies",
|
||||
"idd",
|
||||
"capital",
|
||||
"altSpellings",
|
||||
"region",
|
||||
"subregion",
|
||||
"languages",
|
||||
"translations",
|
||||
"latlng",
|
||||
"landlocked",
|
||||
"borders",
|
||||
"area",
|
||||
"flag",
|
||||
"demonyms"
|
||||
};
|
||||
|
||||
private boolean isEmpty(String value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public class CountryServiceBase {
|
||||
LOG.debug("Loading JSON " + filename);
|
||||
List<BaseCountry> countries = new ArrayList<>();
|
||||
InputStream is = CountryServiceBase.class.getClassLoader().getResourceAsStream(filename);
|
||||
Gson gson = new Gson();
|
||||
var gson = new Gson();
|
||||
JsonReader reader;
|
||||
try {
|
||||
assert is != null;
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
package dev.amatos.restcountries.service.v3;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import dev.amatos.restcountries.domain.ICountryRestSymbols;
|
||||
import dev.amatos.restcountries.v3.domain.Country;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.Normalizer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CountryService {
|
||||
|
||||
private static List<Country> countries;
|
||||
|
||||
private CountryService() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
private static void initialize() {
|
||||
countries = loadJson("countriesV3.json", Country.class);
|
||||
}
|
||||
|
||||
private static class InstanceHolder {
|
||||
|
||||
private static final CountryService INSTANCE = new CountryService();
|
||||
}
|
||||
|
||||
public static CountryService getInstance() {
|
||||
return CountryService.InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public List<Country> getAll() {
|
||||
return countries;
|
||||
}
|
||||
|
||||
public Country getByAlpha(String alpha) {
|
||||
for (var country : countries) {
|
||||
if (country.getCca2().equalsIgnoreCase(alpha) ||
|
||||
country.getCcn3().equalsIgnoreCase(alpha) ||
|
||||
country.getCca3().equalsIgnoreCase(alpha) ||
|
||||
country.getCioc().equalsIgnoreCase(alpha)
|
||||
) {
|
||||
return country;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Country> getByName(String name, boolean isFullText) {
|
||||
if (isFullText) {
|
||||
return fulltextSearch(name, countries);
|
||||
} else {
|
||||
return substringSearch(name, countries);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Country> getByCurrency(String currency) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
country.getCurrencies().forEach((key, value) -> {
|
||||
if (key.equalsIgnoreCase(currency) ||
|
||||
value.getName() != null && value.getName().toLowerCase().contains(currency)
|
||||
) {
|
||||
result.add(country);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Country> fulltextSearch(String name, List<Country> countries) {
|
||||
// Using 2 different 'for' loops to give priority to 'name' matches over alternative spellings
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
if (
|
||||
isNameNormalizedEquals(name, country.getName().getCommon()) ||
|
||||
isNameNormalizedEquals(name, country.getName().getOfficial())
|
||||
) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
for (Country country : countries) {
|
||||
for (String alternative : country.getAltSpellings()) {
|
||||
if (isNameNormalizedEquals(alternative, country.getName().getCommon())
|
||||
&& !result.contains(country)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Country> substringSearch(String name, List<Country> countries) {
|
||||
// Using 2 different 'for' loops to give priority to 'name' matches over alternative spellings
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
if (
|
||||
isNameNormalizedContaining(name, country.getName().getCommon()) ||
|
||||
isNameNormalizedContaining(name, country.getName().getOfficial())
|
||||
) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
for (Country country : countries) {
|
||||
for (String alternative : country.getAltSpellings()) {
|
||||
if (isNameNormalizedContaining(alternative, country.getName().getCommon())
|
||||
&& !result.contains(country)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Country> getByCodeList(String codeList) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
if (codeList == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String[] codes = codeList.split(ICountryRestSymbols.COLON);
|
||||
for (String code : codes) {
|
||||
var country = getByAlpha(code);
|
||||
if (!result.contains(country)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Country> getByCapital(String capital) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
for (String countryCapital : country.getCapital()) {
|
||||
if (normalize(countryCapital.toLowerCase()).contains(normalize(capital.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Country> getByRegion(String subregion) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
if (country.getRegion().equalsIgnoreCase(subregion)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Country> getBySubregion(String region) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
if (country.getSubregion().equalsIgnoreCase(region)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Country> getByLanguage(String language) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
country.getLanguages().forEach((key, value) -> {
|
||||
if (value.equalsIgnoreCase(language) || key.equalsIgnoreCase(language)) {
|
||||
result.add(country);
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Country> getByDemonym(String demonym) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
country.getDemonyms().forEach((key, values) -> values.forEach((k, v)-> {
|
||||
if(v.toLowerCase().contains(demonym.toLowerCase())) {
|
||||
result.add(country);
|
||||
}
|
||||
}));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Country> getByTranslation(String translation) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
country.getTranslations().forEach((key, values) -> values.forEach((k, v)-> {
|
||||
if(v.toLowerCase().contains(translation.toLowerCase())) {
|
||||
result.add(country);
|
||||
}
|
||||
}));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isNameNormalizedEquals(String countryName, String name) {
|
||||
return normalize(countryName.toLowerCase()).equals(name.toLowerCase());
|
||||
}
|
||||
|
||||
private boolean isNameNormalizedContaining(String countryName, String name) {
|
||||
return normalize(countryName.toLowerCase()).contains(name.toLowerCase());
|
||||
}
|
||||
|
||||
protected String normalize(String string) {
|
||||
return Normalizer.normalize(string, Normalizer.Form.NFD)
|
||||
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
|
||||
}
|
||||
|
||||
protected static List<Country> loadJson(String filename, Class<? extends Country> clazz) {
|
||||
InputStream is = CountryService.class.getClassLoader().getResourceAsStream(filename);
|
||||
var gson = new Gson();
|
||||
JsonReader reader;
|
||||
countries = new ArrayList<>();
|
||||
try {
|
||||
assert is != null;
|
||||
reader = new JsonReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
Country country = gson.fromJson(reader, clazz);
|
||||
countries.add(country);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return countries;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,9 @@ import java.util.List;
|
||||
|
||||
public class Country extends BaseCountry {
|
||||
|
||||
private List<dev.amatos.restcountries.v2.domain.Currency> currencies;
|
||||
private List<dev.amatos.restcountries.v2.domain.Language> languages;
|
||||
private dev.amatos.restcountries.v2.domain.Translations translations;
|
||||
private List<Currency> currencies;
|
||||
private List<Language> languages;
|
||||
private Translations translations;
|
||||
private List<String> flags;
|
||||
private List<RegionalBloc> regionalBlocs;
|
||||
private String cioc;
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
package dev.amatos.restcountries.v3.domain;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Country {
|
||||
private Name name;
|
||||
private List<String> tld;
|
||||
private String cca2;
|
||||
private String ccn3;
|
||||
private String cca3;
|
||||
private String cioc;
|
||||
private Boolean independent;
|
||||
private String status;
|
||||
private Boolean unMember;
|
||||
private Map<String, Currency> currencies;
|
||||
private Idd idd;
|
||||
private List<String> capital;
|
||||
private List<String> altSpellings;
|
||||
private String region;
|
||||
private String subregion;
|
||||
private Map<String, String> languages;
|
||||
private Map<String, Map<String, String>> translations;
|
||||
private List<Double> latlng;
|
||||
private Boolean landlocked;
|
||||
private List<String> borders;
|
||||
private Double area;
|
||||
private String flag;
|
||||
private List<String> flags;
|
||||
private Map<String, Map<String, String>> demonyms;
|
||||
private List<String> callingCodes;
|
||||
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<String> getTld() {
|
||||
return tld;
|
||||
}
|
||||
|
||||
public void setTld(List<String> tld) {
|
||||
this.tld = tld;
|
||||
}
|
||||
|
||||
public String getCca2() {
|
||||
return cca2;
|
||||
}
|
||||
|
||||
public void setCca2(String cca2) {
|
||||
this.cca2 = cca2;
|
||||
}
|
||||
|
||||
public String getCcn3() {
|
||||
return ccn3;
|
||||
}
|
||||
|
||||
public void setCcn3(String ccn3) {
|
||||
this.ccn3 = ccn3;
|
||||
}
|
||||
|
||||
public String getCioc() {
|
||||
return cioc;
|
||||
}
|
||||
|
||||
public void setCioc(String cioc) {
|
||||
this.cioc = cioc;
|
||||
}
|
||||
|
||||
public Boolean getIndependent() {
|
||||
return independent;
|
||||
}
|
||||
|
||||
public void setIndependent(Boolean independent) {
|
||||
this.independent = independent;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Boolean getUnMember() {
|
||||
return unMember;
|
||||
}
|
||||
|
||||
public void setUnMember(Boolean unMember) {
|
||||
this.unMember = unMember;
|
||||
}
|
||||
|
||||
public Map<String, Currency> getCurrencies() {
|
||||
return currencies;
|
||||
}
|
||||
|
||||
public void setCurrencies(
|
||||
Map<String, Currency> currencies) {
|
||||
this.currencies = currencies;
|
||||
}
|
||||
|
||||
public Idd getIdd() {
|
||||
return idd;
|
||||
}
|
||||
|
||||
public void setIdd(Idd idd) {
|
||||
this.idd = idd;
|
||||
}
|
||||
|
||||
public List<String> getCapital() {
|
||||
return capital;
|
||||
}
|
||||
|
||||
public void setCapital(List<String> capital) {
|
||||
this.capital = capital;
|
||||
}
|
||||
|
||||
public List<String> getAltSpellings() {
|
||||
return altSpellings;
|
||||
}
|
||||
|
||||
public void setAltSpellings(List<String> altSpellings) {
|
||||
this.altSpellings = altSpellings;
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public String getSubregion() {
|
||||
return subregion;
|
||||
}
|
||||
|
||||
public void setSubregion(String subregion) {
|
||||
this.subregion = subregion;
|
||||
}
|
||||
|
||||
public Map<String, String> getLanguages() {
|
||||
return languages;
|
||||
}
|
||||
|
||||
public void setLanguages(Map<String, String> languages) {
|
||||
this.languages = languages;
|
||||
}
|
||||
|
||||
public List<Double> getLatlng() {
|
||||
return latlng;
|
||||
}
|
||||
|
||||
public void setLatlng(List<Double> latlng) {
|
||||
this.latlng = latlng;
|
||||
}
|
||||
|
||||
public Boolean getLandlocked() {
|
||||
return landlocked;
|
||||
}
|
||||
|
||||
public void setLandlocked(Boolean landlocked) {
|
||||
this.landlocked = landlocked;
|
||||
}
|
||||
|
||||
public List<String> getBorders() {
|
||||
return borders;
|
||||
}
|
||||
|
||||
public void setBorders(List<String> borders) {
|
||||
this.borders = borders;
|
||||
}
|
||||
|
||||
public Double getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public void setArea(Double area) {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public String getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(String flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public List<String> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void setFlags(List<String> flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, String>> getDemonyms() {
|
||||
return demonyms;
|
||||
}
|
||||
|
||||
public void setDemonyms(
|
||||
Map<String, Map<String, String>> demonyms) {
|
||||
this.demonyms = demonyms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Country{" + "\n" +
|
||||
"NativeName=" + name.getNativeName() + "\n" +
|
||||
"Common=" + name.getCommon() + "\n" +
|
||||
"Official=" + name.getOfficial() + "\n" +
|
||||
", tld=" + tld + "\n" +
|
||||
", cca2='" + cca2 + '\'' + "\n" +
|
||||
", ccn3='" + ccn3 + '\'' + "\n" +
|
||||
", cioc='" + cioc + '\'' + "\n" +
|
||||
", independent=" + independent + "\n" +
|
||||
", status='" + status + '\'' + "\n" +
|
||||
", unMember=" + unMember + "\n" +
|
||||
", currencies=" + currencies + "\n" +
|
||||
", idd=" + idd + "\n" +
|
||||
", capital=" + capital + "\n" +
|
||||
", altSpelling=" + altSpellings + "\n" +
|
||||
", region='" + region + '\'' + "\n" +
|
||||
", subregion='" + subregion + '\'' + "\n" +
|
||||
", language=" + languages + "\n" +
|
||||
", latlng=" + latlng + "\n" +
|
||||
", landlocked=" + landlocked + "\n" +
|
||||
", borders=" + borders + "\n" +
|
||||
", area=" + area + "\n" +
|
||||
", flag='" + flag + '\'' + "\n" +
|
||||
", flags=" + flags + "\n" +
|
||||
", demonyms=" + demonyms + "\n" +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getCca3() {
|
||||
return cca3;
|
||||
}
|
||||
|
||||
public void setCca3(String cca3) {
|
||||
this.cca3 = cca3;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, String>> getTranslations() {
|
||||
return translations;
|
||||
}
|
||||
|
||||
public void setTranslations(Map<String, Map<String, String>> translations) {
|
||||
this.translations = translations;
|
||||
}
|
||||
|
||||
public List<String> getCallingCodes() {
|
||||
return callingCodes;
|
||||
}
|
||||
|
||||
public void setCallingCodes(List<String> callingCodes) {
|
||||
this.callingCodes = callingCodes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package dev.amatos.restcountries.v3.domain;
|
||||
|
||||
public class Currency {
|
||||
private String name;
|
||||
private String symbol;
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public void setSymbol(String symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package dev.amatos.restcountries.v3.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Idd {
|
||||
private String root;
|
||||
private List<String> suffixes;
|
||||
|
||||
public String getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public void setRoot(String root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
public List<String> getSuffixes() {
|
||||
return suffixes;
|
||||
}
|
||||
|
||||
public void setSuffixes(List<String> suffixes) {
|
||||
this.suffixes = suffixes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package dev.amatos.restcountries.v3.domain;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Name {
|
||||
private String common;
|
||||
private String official;
|
||||
private Map<String, NativeName> nativeName;
|
||||
|
||||
public String getCommon() {
|
||||
return common;
|
||||
}
|
||||
|
||||
public void setCommon(String common) {
|
||||
this.common = common;
|
||||
}
|
||||
|
||||
public String getOfficial() {
|
||||
return official;
|
||||
}
|
||||
|
||||
public void setOfficial(String official) {
|
||||
this.official = official;
|
||||
}
|
||||
|
||||
public Map<String, NativeName> getNativeName() {
|
||||
return nativeName;
|
||||
}
|
||||
|
||||
public void setNativeName(
|
||||
Map<String, NativeName> nativeName) {
|
||||
this.nativeName = nativeName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package dev.amatos.restcountries.v3.domain;
|
||||
|
||||
public class NativeName {
|
||||
private String official;
|
||||
private String common;
|
||||
|
||||
public String getOfficial() {
|
||||
return official;
|
||||
}
|
||||
|
||||
public void setOfficial(String official) {
|
||||
this.official = official;
|
||||
}
|
||||
|
||||
public String getCommon() {
|
||||
return common;
|
||||
}
|
||||
|
||||
public void setCommon(String common) {
|
||||
this.common = common;
|
||||
}
|
||||
}
|
||||
@@ -20427,5 +20427,96 @@
|
||||
"hu": "Zimbabwe"
|
||||
},
|
||||
"cioc": "ZIM"
|
||||
},
|
||||
{
|
||||
"alpha2Code": "HK",
|
||||
"alpha3Code": "HKG",
|
||||
"altSpellings": [
|
||||
"HK"
|
||||
],
|
||||
"borders": [
|
||||
"CHN"
|
||||
],
|
||||
"callingCodes": [
|
||||
"970"
|
||||
],
|
||||
"capital": "Ramallah",
|
||||
"currencies": [
|
||||
{
|
||||
"code": "EGP",
|
||||
"name": "Egyptian pound",
|
||||
"symbol": "\u0045\u00a3"
|
||||
},
|
||||
{
|
||||
"code": "ILS",
|
||||
"name": "Israeli new shekel",
|
||||
"symbol": "\u20aa"
|
||||
},
|
||||
{
|
||||
"code": "JOD",
|
||||
"name": "Jordanian dinar",
|
||||
"symbol": "\u062f\u002e\u0623"
|
||||
}
|
||||
],
|
||||
"demonym": "Palestinian",
|
||||
"independent": true,
|
||||
"flags": [
|
||||
"https://restcountries.com/data/pse.svg",
|
||||
"https://restcountries.com/data/png/pse.png"
|
||||
],
|
||||
"gini": 35.5,
|
||||
"languages": [
|
||||
{
|
||||
"iso639_1": "ar",
|
||||
"iso639_2": "ara",
|
||||
"name": "Arabic",
|
||||
"nativeName": "\u0627\u0644\u0639\u0631\u0628\u064a\u0629"
|
||||
}
|
||||
],
|
||||
"latlng": [
|
||||
31.9,
|
||||
35.2
|
||||
],
|
||||
"name": "Palestine, State of",
|
||||
"nativeName": "\u0641\u0644\u0633\u0637\u064a\u0646",
|
||||
"numericCode": "275",
|
||||
"population": 5159076,
|
||||
"continent": "Asia",
|
||||
"regionalBlocs": [
|
||||
{
|
||||
"acronym": "AL",
|
||||
"name": "Arab League",
|
||||
"otherNames": [
|
||||
"\u062c\u0627\u0645\u0639\u0629 \u0627\u0644\u062f\u0648\u0644 \u0627\u0644\u0639\u0631\u0628\u064a\u0629",
|
||||
"J\u0101mi\u02bbat ad-Duwal al-\u02bbArab\u012byah",
|
||||
"League of Arab States"
|
||||
]
|
||||
}
|
||||
],
|
||||
"region": "Western Asia",
|
||||
"timezones": [
|
||||
"UTC+02:00"
|
||||
],
|
||||
"topLevelDomain": [
|
||||
".ps"
|
||||
],
|
||||
"translations": {
|
||||
"br": "Palestina",
|
||||
"de": "Pal\u00e4stina",
|
||||
"es": "Palestina",
|
||||
"fa": "\u0641\u0644\u0633\u0637\u06cc\u0646",
|
||||
"fr": "Palestine",
|
||||
"hr": "Palestina",
|
||||
"it": "Palestina",
|
||||
"ja": "\u30d1\u30ec\u30b9\u30c1\u30ca",
|
||||
"nl": "Palestijnse gebieden",
|
||||
"pt": "Palestina",
|
||||
"hu": "Palesztina"
|
||||
},
|
||||
"cioc": "PLE",
|
||||
"maps": {
|
||||
"gmaps": "https://www.google.com/maps/place/Palestina/@31.9511089,34.5815707,9z",
|
||||
"openstreetmap": "https://www.openstreetmap.org/relation/1703814"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<withJansi>true</withJansi>
|
||||
<withJansi>false</withJansi>
|
||||
<!-- encoders are assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
||||
<encoder>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="520" height="340" viewBox="0 0 260 170">
|
||||
<rect fill="#0064AE" width="260" height="170"/>
|
||||
<g fill="#FFD300">
|
||||
<rect x="80" width="50" height="170"/>
|
||||
<rect y="60" width="260" height="50"/>
|
||||
</g>
|
||||
<g fill="#DB0F16">
|
||||
<rect x="95" width="20" height="170"/>
|
||||
<rect y="75" width="260" height="20"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 386 B |
Binary file not shown.
|
After Width: | Height: | Size: 328 B |
@@ -3,7 +3,7 @@ REST Countries 🇵🇪
|
||||
|
||||
Get information about countries via a RESTful API
|
||||
|
||||
*Current version: 1*
|
||||
*Current version: 3*
|
||||
|
||||
Donate!
|
||||
---------------
|
||||
@@ -32,7 +32,341 @@ Original RESTCountries project has over 1200 users, including:
|
||||
- [onefinestay]
|
||||
- [Much Better Adventures]
|
||||
|
||||
API Endpoints
|
||||
API Endpoints v3
|
||||
=======
|
||||
|
||||
This version takes countries from [this] project, but it adds the flags. Although the requests
|
||||
have not changed much, the response has as the country structure is different.
|
||||
|
||||
All
|
||||
---------------
|
||||
``` html
|
||||
https://restcountries.com/v3/all
|
||||
```
|
||||
|
||||
Name
|
||||
---------------
|
||||
|
||||
Search by country name. It can be the native name or partial name
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/name/{name}
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/name/peru
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/name/united
|
||||
```
|
||||
|
||||
Full Name
|
||||
---------------
|
||||
|
||||
Search by country full name
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/name/{name}?fullText=true
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/name/aruba?fullText=true
|
||||
```
|
||||
|
||||
Code
|
||||
---------------
|
||||
|
||||
Search by cca2, ccn3, cca3 or cioc country code (yes, any!)
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha/{code}
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha/pe
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha/per
|
||||
```
|
||||
|
||||
List of codes
|
||||
---------------
|
||||
|
||||
Search by list of cca2, ccn3, cca3 or cioc country codes (yes, any!). The original project used *;* as
|
||||
separator. In out case, the *comma* is used to separate values.
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha?codes={code},{code},{code}
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha?codes=col,pe,at
|
||||
```
|
||||
|
||||
List of codes
|
||||
---------------
|
||||
|
||||
Search by list of cca2, ccn3, cca3 or cioc country codes (yes, any!). The original project used *;* as
|
||||
separator. In out case, the *comma* is used to separate values.
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha?codes={code},{code},{code}
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha?codes=col,pe,at
|
||||
```
|
||||
|
||||
Currency
|
||||
---------------
|
||||
|
||||
Search by currency name (_new!_) or code
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/currency/{currency}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/currency/pen
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/currency/dollar
|
||||
```
|
||||
|
||||
Language
|
||||
---------------
|
||||
|
||||
Search by language name (_new!_) or iso639_2 code
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/lang/{lang}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/lang/spa
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/lang/german
|
||||
```
|
||||
|
||||
Translations (new!)
|
||||
-
|
||||
Now you can search by name in any available translation
|
||||
``` html
|
||||
https://restcountries.com/v3/translation/Peruánská
|
||||
```
|
||||
|
||||
Capital city
|
||||
---------------
|
||||
|
||||
Search by capital city.
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/capital/{capital}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/capital/lima
|
||||
```
|
||||
|
||||
Region
|
||||
---------------
|
||||
|
||||
Search by Region: Africa, Americas, Asia, Europe, Oceania
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/continent/{region}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/continent/europe
|
||||
```
|
||||
|
||||
Subregion
|
||||
---------------
|
||||
|
||||
Search by Subregion: South America, Southern Europe, Central America, Eastern Asia, etc.
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/continent/{region}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/continent/europe
|
||||
```
|
||||
|
||||
Demonym
|
||||
-
|
||||
Now you can search by how a citizen is called.
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/demonym/{region}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/demonym/peruvian
|
||||
```
|
||||
|
||||
Response Example
|
||||
-
|
||||
``` html
|
||||
https://restcountries.com/v3/name/japan
|
||||
```
|
||||
``` html
|
||||
[
|
||||
{
|
||||
"name": {
|
||||
"common": "Japan",
|
||||
"official": "Japan",
|
||||
"nativeName": {
|
||||
"jpn": {
|
||||
"official": "日本",
|
||||
"common": "日本"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tld": [
|
||||
".jp",
|
||||
".みんな"
|
||||
],
|
||||
"cca2": "JP",
|
||||
"ccn3": "392",
|
||||
"cca3": "JPN",
|
||||
"cioc": "JPN",
|
||||
"independent": true,
|
||||
"status": "officially-assigned",
|
||||
"unMember": true,
|
||||
"currencies": {
|
||||
"JPY": {
|
||||
"name": "Japanese yen",
|
||||
"symbol": "¥"
|
||||
}
|
||||
},
|
||||
"idd": {
|
||||
"root": "+8",
|
||||
"suffixes": [
|
||||
"1"
|
||||
]
|
||||
},
|
||||
"capital": [
|
||||
"Tokyo"
|
||||
],
|
||||
"altSpellings": [
|
||||
"JP",
|
||||
"Nippon",
|
||||
"Nihon"
|
||||
],
|
||||
"region": "Asia",
|
||||
"subregion": "Eastern Asia",
|
||||
"languages": {
|
||||
"jpn": "Japanese"
|
||||
},
|
||||
"translations": {
|
||||
"ces": {
|
||||
"official": "Japonsko",
|
||||
"common": "Japonsko"
|
||||
},
|
||||
"deu": {
|
||||
"official": "Japan",
|
||||
"common": "Japan"
|
||||
},
|
||||
"est": {
|
||||
"official": "Jaapan",
|
||||
"common": "Jaapan"
|
||||
},
|
||||
"fin": {
|
||||
"official": "Japani",
|
||||
"common": "Japani"
|
||||
},
|
||||
"fra": {
|
||||
"official": "Japon",
|
||||
"common": "Japon"
|
||||
},
|
||||
"hrv": {
|
||||
"official": "Japan",
|
||||
"common": "Japan"
|
||||
},
|
||||
"hun": {
|
||||
"official": "Japán",
|
||||
"common": "Japán"
|
||||
},
|
||||
"ita": {
|
||||
"official": "Giappone",
|
||||
"common": "Giappone"
|
||||
},
|
||||
"jpn": {
|
||||
"official": "日本",
|
||||
"common": "日本"
|
||||
},
|
||||
"kor": {
|
||||
"official": "일본국",
|
||||
"common": "일본"
|
||||
},
|
||||
"nld": {
|
||||
"official": "Japan",
|
||||
"common": "Japan"
|
||||
},
|
||||
"per": {
|
||||
"official": "ژاپن",
|
||||
"common": "ژاپن"
|
||||
},
|
||||
"pol": {
|
||||
"official": "Japonia",
|
||||
"common": "Japonia"
|
||||
},
|
||||
"por": {
|
||||
"official": "Japão",
|
||||
"common": "Japão"
|
||||
},
|
||||
"rus": {
|
||||
"official": "Япония",
|
||||
"common": "Япония"
|
||||
},
|
||||
"slk": {
|
||||
"official": "Japonsko",
|
||||
"common": "Japonsko"
|
||||
},
|
||||
"spa": {
|
||||
"official": "Japón",
|
||||
"common": "Japón"
|
||||
},
|
||||
"swe": {
|
||||
"official": "Japan",
|
||||
"common": "Japan"
|
||||
},
|
||||
"urd": {
|
||||
"official": "جاپان",
|
||||
"common": "جاپان"
|
||||
},
|
||||
"zho": {
|
||||
"official": "日本国",
|
||||
"common": "日本"
|
||||
}
|
||||
},
|
||||
"latlng": [
|
||||
36.0,
|
||||
138.0
|
||||
],
|
||||
"landlocked": false,
|
||||
"area": 377930.0,
|
||||
"flag": "🇯🇵",
|
||||
"flags": [
|
||||
"https://restcountries.com/data/jpn.svg",
|
||||
"https://restcountries.com/data/png/jpn.png"
|
||||
],
|
||||
"demonyms": {
|
||||
"eng": {
|
||||
"f": "Japanese",
|
||||
"m": "Japanese"
|
||||
},
|
||||
"fra": {
|
||||
"f": "Japonaise",
|
||||
"m": "Japonais"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
---------------------
|
||||
|
||||
API Endpoints v2
|
||||
=======
|
||||
|
||||
Below are described the REST endpoints available that you can use to search for countries
|
||||
@@ -49,7 +383,7 @@ Name
|
||||
|
||||
Search by country name. It can be the native name or partial name
|
||||
|
||||
``` javascript
|
||||
``` html
|
||||
https://restcountries.com/v2/name/{name}
|
||||
```
|
||||
|
||||
@@ -66,7 +400,7 @@ Full Name
|
||||
|
||||
Search by country full name
|
||||
|
||||
``` javascript
|
||||
``` html
|
||||
https://restcountries.com/v2/name/{name}?fullText=true
|
||||
```
|
||||
|
||||
@@ -79,7 +413,7 @@ Code
|
||||
|
||||
Search by ISO 3166-1 2-letter or 3-letter country code
|
||||
|
||||
``` javascript
|
||||
``` html
|
||||
https://restcountries.com/v2/alpha/{code}
|
||||
```
|
||||
|
||||
@@ -97,7 +431,7 @@ List of codes
|
||||
Search by list of ISO 3166-1 2-letter or 3-letter country codes. The original project used *;* as
|
||||
separator. In out case, the *comma* is used to separate values.
|
||||
|
||||
``` javascript
|
||||
``` html
|
||||
https://restcountries.com/v2/alpha?codes={code},{code},{code}
|
||||
```
|
||||
|
||||
@@ -110,7 +444,7 @@ Currency
|
||||
|
||||
Search by ISO 4217 currency code
|
||||
|
||||
``` javascript
|
||||
``` html
|
||||
https://restcountries.com/v2/currency/{currency}
|
||||
```
|
||||
``` html
|
||||
@@ -134,7 +468,7 @@ Capital city
|
||||
|
||||
Search by capital city
|
||||
|
||||
``` javascript
|
||||
``` html
|
||||
https://restcountries.com/v2/capital/{capital}
|
||||
```
|
||||
``` html
|
||||
@@ -184,7 +518,7 @@ Search by regional bloc:
|
||||
- NAFTA (North American Free Trade Agreement)
|
||||
- SAARC (South Asian Association for Regional Cooperation)
|
||||
|
||||
``` javascript
|
||||
``` html
|
||||
https://restcountries.com/v2/regionalbloc/{regionalbloc}
|
||||
```
|
||||
``` html
|
||||
@@ -359,4 +693,5 @@ License
|
||||
[FxPro]: http://www.fxpro.com/
|
||||
[onefinestay]: https://www.onefinestay.com/
|
||||
[Much Better Adventures]: https://www.muchbetteradventures.com
|
||||
[SKROSS]: http://www.skross.com/en
|
||||
[SKROSS]: http://www.skross.com/en
|
||||
[this]: https://github.com/mledoze/countries
|
||||
@@ -45,8 +45,8 @@
|
||||
<div class='left'>
|
||||
<h1>REST Countries</h1>
|
||||
<ul>
|
||||
<li><a href='https://github.com/apilayer/restcountries'>View on GitHub</a></li>
|
||||
<li><a href='https://github.com/apilayer/restcountries/issues'>Issues</a></li>
|
||||
<li><a href='https://gitlab.com/amatos/rest-countries'>View on GitLab</a></li>
|
||||
<li><a href='https://gitlab.com/amatos/rest-countries/-/issues'>Issues</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user