RESTful web-services to get and search Countries

148304
Mar 20, 2016

Many web application and desktop applications need to show a list of countries and its states. Here is list of free REST web-services to consume for this purpose.

1. REST web-service to get a list of all Countries


Each country has 2 character and 3 character ISO assigned code. Below service has all the county name, 2 character code and 3 character assigned code.

http://services.groupkt.com/country/get/all



This rest web service will return a list countries in JSON format, each country object has

{
"name":"India",
"alpha2_code":"IN",
"alpha3_code":"IND"
}




2. REST web-service to search country by 2 character alphanumeric ISO code


To search the Country by its 2 character alphanumeric assigned, this REST web-service can be used, it will return a JSON Country object matching the requested 2 character alphanumeric code.


The url for this web service is http://services.groupkt.com/country/get/iso2code/{alpha2_code} for example

http://services.groupkt.com/country/get/iso2code/IN



This rest web service will search and return the matching country having same same 2 character ISO code as requested in JSON format. the example of search result is

{
"RestResponse" : {
"messages" : [ "Country found matching code [IN]." ],
"result" : {
"name" : "India",
"alpha2_code" : "IN",
"alpha3_code" : "IND"
}
}
}


and if nothing matching found then

{
"RestResponse" : {
"messages" : [ "No matching country found for requested code [IU]." ]
}
}





3. REST web-service to search country by 3 character alphanumeric ISO code


To search the Country by its 3 character alphanumeric assigned,


The url for this web service is http://services.groupkt.com/country/get/iso3code/{alpha3_code} for example

http://services.groupkt.com/country/get/iso3code/IND



This rest web service will search and return the matching country

{
"RestResponse" : {
"messages" : [ "Country found matching code [IND]." ],
"result" : {
"name" : "India",
"alpha2_code" : "IN",
"alpha3_code" : "IND"
}
}
}


and if nothing matching found then

{
"RestResponse" : {
"messages" : [ "No matching country found for requested code [XYZ]." ]
}
}




4. REST web-service to search country by 3 character ISO code or 2 character ISO code or country name


This will search the input string every where in all 2 ISO codes and country name. partial input is also allowed


The url for this web service is http://services.groupkt.com/country/search?text={text to search} for example

http://services.groupkt.com/country/search?text=un



This rest web service will search and return the matching country

{
"RestResponse" : {
"messages" : [ "Total [12] records found." ],
"result" : [ {
"name" : "Brunei Darussalam",
"alpha2_code" : "BN",
"alpha3_code" : "BRN"
}, {
"name" : "Burundi",
"alpha2_code" : "BI",
"alpha3_code" : "BDI"
}, {
"name" : "Hungary",
"alpha2_code" : "HU",
"alpha3_code" : "HUN"
}, {
"name" : "RĂ©union",
"alpha2_code" : "RE",
"alpha3_code" : "REU"
}, {
"name" : "Saint Helena, Ascension and Tristan da Cunha",
"alpha2_code" : "SH",
"alpha3_code" : "SHN"
}, {
"name" : "Tanzania, United Republic of",
"alpha2_code" : "TZ",
"alpha3_code" : "TZA"
}, {
"name" : "Tunisia",
"alpha2_code" : "TN",
"alpha3_code" : "TUN"
}, {
"name" : "United Arab Emirates",
"alpha2_code" : "AE",
"alpha3_code" : "ARE"
}, {
"name" : "United Kingdom",
"alpha2_code" : "GB",
"alpha3_code" : "GBR"
}, {
"name" : "United States",
"alpha2_code" : "US",
"alpha3_code" : "USA"
}, {
"name" : "United States Minor Outlying Islands",
"alpha2_code" : "UM",
"alpha3_code" : "UMI"
}, {
"name" : "Wallis and Futuna",
"alpha2_code" : "WF",
"alpha3_code" : "WLF"
} ]
}
}


and if nothing matching found then

{
"RestResponse" : {
"messages" : [ "No matching country found for requested code [xx]." ]
}
}





To test above service just click the example link or copy/paste the example link in browser address bar and you will get the JSON Rest response.
If you are using Java,then you can integrate this web service with your code either by using Springs's org.springframework.web.client.RestTemplate or Apache's HTTPClient
You can refer http://www.groupkt.com/post/f2129b88/free-restful-web-services.htm for more REST services.

* Web Service to get location by IP




comments powered by Disqus

© Copyright 2017