Introduction
Welcome to the documentation for CountrySource – a comprehensive data source for country information. CountrySource provides APIs that allow you to access various data points about countries all around the world.
Installation
To use CountrySource, follow the steps below:
- Register for an API key on the CountrySource website.
- Download and install the CountrySource SDK from the official GitHub repository.
- Include the SDK in your project by adding the necessary dependencies.
- Import the required classes and methods into your code.
- Initialize the CountrySource client with your API key.
Usage
Once you have installed the CountrySource SDK and included it in your project, you can start using the available APIs to retrieve country information. Follow the example below to get started:
<?php // Import necessary classes use CountrySource\Client; // Initialize the client with your API key $client = new Client('YOUR_API_KEY'); // Retrieve a list of all countries $countries = $client->getCountries(); // Process the retrieved data foreach($countries as $country) { echo "Country Name: " . $country['name'] . "\n"; echo "Capital: " . $country['capital'] . "\n"; echo "Population: " . $country['population'] . "\n\n"; } ?>
APIs
CountrySource provides the following APIs to access country information:
API: getCountries()
Returns a list of all countries along with their basic information.
Parameters
This API does not require any parameters.
Returns
An array of country objects, where each object contains the following information:
- name: The name of the country
- capital: The capital of the country
- population: The population of the country
[ { "name": "Afghanistan", "capital": "Kabul", "population": 27657145 }, { "name": "Albania", "capital": "Tirana", "population": 2886026 }, ... ]
API: getCountryByName($countryName)
Returns detailed information about a specific country.
Parameters
$countryName: The name of the country to retrieve information about.
Returns
An object containing detailed information about the specified country, including:
- name: The name of the country
- capital: The capital of the country
- population: The population of the country
- area: The total area of the country in square kilometers
- currency: The currency used in the country
- languages: An array of languages spoken in the country
- timezones: An array of timezones followed in the country
- borders: An array of countries that share borders with the country
{ "name": "India", "capital": "New Delhi", "population": 1295210000, "area": 3287590, "currency": "Indian Rupee", "languages": [ "Hindi", "English" ], "timezones": [ "UTC+05:30" ], "borders": [ "Bangladesh", "Bhutan", "Myanmar", "China", "Nepal", "Pakistan" ] }
API: getCountryByCode($countryCode)
Returns detailed information about a specific country based on its ISO 3166-1 alpha-2 country code.
Parameters
$countryCode: The ISO 3166-1 alpha-2 country code of the country to retrieve information about.
Returns
Returns an object containing detailed information about the specified country. The structure of the returned object is the same as the one returned by the getCountryByName
API.
API: getCountryByCurrency($currencyName)
Returns a list of countries that use a specific currency.
Parameters
$currencyName: The name of the currency to search for.
Returns
An array of country objects that use the specified currency. Each country object contains the basic information of a country, similar to the objects returned by the getCountries
API.
API: getCountryByLanguage($languageName)
Returns a list of countries where a specific language is spoken.
Parameters
$languageName: The name of the language to search for.
Returns
An array of country objects where the specified language is spoken. Each country object contains the basic information of a country, similar to the objects returned by the getCountries
API.
Conclusion
Congratulations! You now have access to a comprehensive data source for country information using CountrySource. Explore the available APIs to retrieve information about countries, and integrate this data into your projects seamlessly.