Building a dynamic application is becoming a requirement for every business to stay competitive in the marketplace. Long gone are the days where an application should be developed for a specific country, city, or language. Indeed, in today’s software development landscape, dynamic applications can easily detect the user’s local time zone, language, country, continent, and city. This information will help in serving the users the content and interface that is intended for their region. Behind this dynamic revolution in app development are APIs that contain data about different locations and areas of the world.
One of these APIs is the Referential Application Programming Interface that provides the needed data to help create dynamic applications that need country, city, time zone, and additional geographic information to serve the user. This article will introduce the main features, operating mechanisms, and workflows of the Referential API. Furthermore, this tutorial will provide you with the needed information to test the Referential API using Python, PHP, Ruby, or JavaScript.
Referential API Definition
The Referential Application Programming Interface allows developers to collect a comprehensive list of cities, states, continents, countries, time zones, and languages. In addition, the Referential API can extract a single city, country, continent, time zones, and language based on name or ID.
Referential API is centered on geographic and location-based information as the principal data point that it serves and retrieves. Indeed, every API call will return location-based information. In addition, the Referential API allows the retrieval of a city based on an IP address. To explain, based on a given IP address, the Referential API will return what is known as city GEO IP or the city name based on the IP address.
Referential API Operating Mechanism
The Referential API operates under the HTTP methods infrastructure. For instance, for a developer to retrieve 75 000 cities, a GET request will be initiated to return the needed cities information. This workflow is consistent in all Referential API endpoints as all requests initiate a GET request.
Requesting data is only the first step of the Referential API operation. To elaborate, once the information is retrieved, this data should be processed and parsed. In our case, the data returned will take the form of a JSON (JavaScript Object Notation) file that can be easily parsed and processed using Python, PHP, Ruby, or JavaScript.
Referential API Users
The primary intended users of the Referential API are app developers or software engineers who are directly interested in developing mobile or web applications using geographic information, including but not limited to countries, cities, continents, time zones, currencies, and languages. For instance, the following users are considered intended users for the Referential API:
Academic Researchers: In educational research, geographic data is used to understand population movement, density, and cultural differences. One of the use cases of the Referential API will be utilizing this tool to understand the distribution of IP addresses across different continents, countries, and cities.
App Developers: App developers or software engineers are consistently looking for APIs to simplify some of the main repeated tasks used in developing web or mobile applications. To explain, the Referential API eliminates the complexity behind collecting geographic information needed to create applications that can target an international market. For example, a reading application needs to detect your local language using your IP address automatically. The Referential API provides IP-based localization data used for this task.
The Referential API is a valuable data collection tool that can create global applications. These mobile or web applications can benefit significantly from the different data points the Referential API provides, such as IP-based city geolocation, countries, continent, or even foreign currencies based on location or ID. Having a more international application is a great way to increase the number of users targeted to use that particular application from different countries, cities, and continents.
Connect to the Referential API Tutorial
In the following section, we will cover a step-by-step tutorial that will help you get up and running with the Referential API using the RapidAPI platform and code examples:
Step 01. Create An Account In The RapidAPI Platform
Initially, you will need to create an account in the RapidAPI platform using your email, password, and username. Furthermore, Google, GitHub, and Facebook automatic social Signups can be used for instant registration using your preferred social account.
Step 02. Search For The Referential API In The Marketplace
The next step is to find the Referential API in the API marketplace by searching for this API using the keyword Referential. This search query will return the Referential API, which can then be selected from the results list.
Step 03. Test the Referential API using Code Examples
The Referential API can be tested by clicking on the different endpoints and inspecting the provided documentation. In addition, every endpoint comes with a code example in various programming languages and implementations. One of the strategies you can follow is to copy the code example and paste it into your Integrated Development Environment (IDE) or favorite code editor to test it live on your machine.
The following are the different code examples in the Referential API covered in Python, PHP, Ruby, and JavaScript.
Referential API with Python
Make sure that all the required Python environment variables are installed in your operating system. In addition, it is highly recommended to use the latest Python programming language version to avoid any version dependency issues.
GET Cities
import requests url = "https://referential.p.rapidapi.com/v1/city" querystring = {"fields":"iso_a2,state_code,state_hasc,timezone,timezone_offset","iso_a2":"us","lang":"en","state_code":"US-CA","prefix":"san fr"} headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
GET City by IP address (Geo IP)
import requests url = "https://referential.p.rapidapi.com/v1/city" querystring = {"ip":"128.218.229.26"} headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
GET City by id
import requests url = "https://referential.p.rapidapi.com/v1/city/DULUTH%7CUS-GA" querystring = {"lang":"en","fields":"iso_a2,state_code,state_hasc,timezone, timezone_offset"} headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
GET State
import requests url = "https://referential.p.rapidapi.com/v1/state" querystring = {"fields":"iso_a2","name":"tex","iso_a2":"us","lang":"en"} headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
GET Continents
import requests url = "https://referential.p.rapidapi.com/v1/continent" headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers) print(response.text)
GET Continent by id
import requests url = "https://referential.p.rapidapi.com/v1/continent/NA" headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers) print(response.text)
GET State by id
import requests url = "https://referential.p.rapidapi.com/v1/state/US-MN" headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers) print(response.text)
GET Countries
import requests url = "https://referential.p.rapidapi.com/v1/country" querystring = {"fields":"currency,currency_num_code,currency_code,continent_code,currency,iso_a3,dial_code"} headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
GET Country by iso code
import requests url = "https://referential.p.rapidapi.com/v1/country/US" querystring = {"lang":"en"} headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
GET Timezones
import requests url = "https://referential.p.rapidapi.com/v1/timezone" querystring = {"fields":"offset,daylights_offset,daylights,daylights_code,timezone","lang":"de"} headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
GET Timezone by id
import requests url = "https://referential.p.rapidapi.com/v1/timezone/Afrika/Dakar" querystring = {"fields":"offset,daylights_offset,daylights,daylights_code,timezone","lang":"de"} headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
GET Language by id
import requests url = "https://referential.p.rapidapi.com/v1/lang/es" querystring = {"lang":"sv","fields":"iso_a2,lang_3,flag"} headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
GET Languages
import requests url = "https://referential.p.rapidapi.com/v1/lang" querystring = {"fields":"iso_a2,lang_3,flag","lang":"en"} headers = { 'x-rapidapi-host': "referential.p.rapidapi.com", 'x-rapidapi-key': "undefined" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
Referential API with PHP
In this subsection, we will run the Referential API using the PHP programming language. You must have all the needed installations and dependencies required to run PHP code programming environment. In addition, make sure to have the latest version of PHP installed and configured to avoid any errors.
GET Cities
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/city?fields=iso_a2%2Cstate_code%2Cstate_hasc%2Ctimezone%2Ctimezone_offset&iso_a2=us&lang=en&state_code=US-CA&prefix=san%20fr", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET City by IP address (Geo IP)
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/city?ip=128.218.229.26", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET City by id
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/city/DULUTH%7CUS-GA?lang=en&fields=iso_a2%2Cstate_code%2Cstate_hasc%2Ctimezone%2C%20timezone_offset", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET State
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/state?fields=iso_a2&name=tex&iso_a2=us&lang=en", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET Continents
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/continent", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET Continent by id
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/continent/NA", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET State by id
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/state/US-MN", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET Countries
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/country?fields=currency%2Ccurrency_num_code%2Ccurrency_code%2Ccontinent_code%2Ccurrency%2Ciso_a3%2Cdial_code", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET Country by iso code
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/country/US?lang=en", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET Timezones
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/timezone?fields=offset%2Cdaylights_offset%2Cdaylights%2Cdaylights_code%2Ctimezone&lang=de", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET Timezone by id
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/timezone/Afrika/Dakar?fields=offset%2Cdaylights_offset%2Cdaylights%2Cdaylights_code%2Ctimezone&lang=de", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET Language by id
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/lang/es?lang=sv&fields=iso_a2%2Clang_3%2Cflag", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
GET Languages
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://referential.p.rapidapi.com/v1/lang?fields=iso_a2%2Clang_3%2Cflag&lang=en", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: referential.p.rapidapi.com", "x-rapidapi-key: undefined" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
Referential API with Ruby
Make sure you have Ruby installed in your system to test the following sample code. Keep in mind that the installation can be done by following the official Ruby documentation to avoid any installation errors.
GET Cities
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/city?fields=iso_a2%2Cstate_code%2Cstate_hasc%2Ctimezone%2Ctimezone_offset&iso_a2=us&lang=en&state_code=US-CA&prefix=san%20fr") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET City by IP address (Geo IP)
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/city?ip=128.218.229.26") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET City by id
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/city/DULUTH%7CUS-GA?lang=en&fields=iso_a2%2Cstate_code%2Cstate_hasc%2Ctimezone%2C%20timezone_offset") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET State
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/state?fields=iso_a2&name=tex&iso_a2=us&lang=en") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET Continents
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/continent") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET Continent by id
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/continent/NA") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET State by id
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/state/US-MN") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET Countries
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/country?fields=currency%2Ccurrency_num_code%2Ccurrency_code%2Ccontinent_code%2Ccurrency%2Ciso_a3%2Cdial_code") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET Country by iso code
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/country/US?lang=en") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET Timezones
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/timezone?fields=offset%2Cdaylights_offset%2Cdaylights%2Cdaylights_code%2Ctimezone&lang=de") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET Timezone by id
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/timezone/Afrika/Dakar?fields=offset%2Cdaylights_offset%2Cdaylights%2Cdaylights_code%2Ctimezone&lang=de") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET Language by id
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/lang/es?lang=sv&fields=iso_a2%2Clang_3%2Cflag") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
GET Languages
require 'uri' require 'net/http' require 'openssl' url = URI("https://referential.p.rapidapi.com/v1/lang?fields=iso_a2%2Clang_3%2Cflag&lang=en") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-host"] = 'referential.p.rapidapi.com' request["x-rapidapi-key"] = 'undefined' response = http.request(request) puts response.read_body
Referential API with JavaScript
In this subsection, we will run the Referential API using the PHP programming language. You must have all the needed installations and dependencies required to run PHP code programming environment. In addition, make sure to have the latest version of PHP installed and configured to avoid any errors.
GET Cities
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/city?fields=iso_a2%2Cstate_code%2Cstate_hasc%2Ctimezone%2Ctimezone_offset&iso_a2=us&lang=en&state_code=US-CA&prefix=san%20fr", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET City by IP address (Geo IP)
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/city?ip=128.218.229.26", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET City by id
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/city/DULUTH%7CUS-GA?lang=en&fields=iso_a2%2Cstate_code%2Cstate_hasc%2Ctimezone%2C%20timezone_offset", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET State
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/state?fields=iso_a2&name=tex&iso_a2=us&lang=en", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET Continents
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/continent", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET Continent by id
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/continent/NA", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET State by id
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/state/US-MN", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET Countries
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/country?fields=currency%2Ccurrency_num_code%2Ccurrency_code%2Ccontinent_code%2Ccurrency%2Ciso_a3%2Cdial_code", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET Country by iso code
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/country/US?lang=en", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET Timezones
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/timezone?fields=offset%2Cdaylights_offset%2Cdaylights%2Cdaylights_code%2Ctimezone&lang=de", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET Timezone by id
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/timezone/Afrika/Dakar?fields=offset%2Cdaylights_offset%2Cdaylights%2Cdaylights_code%2Ctimezone&lang=de", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET Language by id
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/lang/es?lang=sv&fields=iso_a2%2Clang_3%2Cflag", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
GET Languages
const settings = { "async": true, "crossDomain": true, "url": "https://referential.p.rapidapi.com/v1/lang?fields=iso_a2%2Clang_3%2Cflag&lang=en", "method": "GET", "headers": { "x-rapidapi-host": "referential.p.rapidapi.com", "x-rapidapi-key": "undefined" } }; $.ajax(settings).done(function (response) { console.log(response); });
Referential API Endpoints
The Referential API can be accessed via ten endpoints that can be outlined as follows:
Geography API Endpoints
Cities: This endpoint allows the user to collect various city information complied in 20 different languages. Each city name, state, time zone, and more city-related information can be collected and displayed.
City by IP address (Geo IP): This endpoint allows the user to collect city information using a predefined IP address. To explain, this endpoint provides a direct way to use Geo IP capabilities to identify a city and its related information by simply searching the city using a given IP address.
City by id: This endpoint allows the user to collect city information using a predefined variable known as a city identifier. To explain, each city provided by the Referential API can be extracted using a unique identifier known as city ID. In fact, this endpoint allows the collection of city information using this unique ID.
State: This endpoint allows collecting the compilation of state or region-related information. This endpoint will return these details as key-value pairs identifying the state id as the key and state name as the value.
Continents: This endpoint allows the user to collect the compilation of world continents returned in the user’s preferred language.
Continent by id: This endpoint allows the user to return a continent using a predefined variable known as continent id. Indeed, each continent provided by the Referential API can be extracted using a unique identifier known as continent ID.
State by id: This endpoint allows the user to return a state name using a predefined variable known as the state identification key.
Countries: This endpoint allows the user to collect various country’s information. For each country, continent code, currency code, name, and more country-related information can be collected and displayed.
Country by ISO code: This endpoint allows the collection of country names using a specific ISO code. To explain, this endpoint links every country with its given 2 letter ISO identifier. In fact, these details will be returned as key-value pairs identifying two-letter ISO code as the key and country name as the value.
Locale API Endpoints
Timezones: This endpoint allows the user to collect various time zones compiled in 20 different languages. For each time zone location, time zone name and more time zone-related information can be collected and displayed.
Timezone by id: This endpoint allows the user to collect time zone-related information using a predefined variable known as a language identifier. To explain, to extract a given time zone the continent and location of the time zone will be inputted; in return, the time zone will be identified and displayed.
Language by id: This endpoint allows the user to collect language information using a predefined variable known as language id. To explain, to extract a given language, the language id will be inputted in return the language name, flag, ISO code, and key will be returned.
Languages: This endpoint allows the user to collect a comprehensive list of the world’s languages. For each language, flag, language name, and more language-related information can be collected and displayed.
Benefits of the Referential API
The Referential API opens the door for many benefits directly linked to mobile or web application performance, not to forget the quality of user interface and experience. To start, developers around the globe are always looking for data to optimize the development process and create a dynamic user experience for every app they develop. To explain, location-based data helps create practical dynamic applications used to serve users from different countries, cities and using their local language. In addition, geographic data allow application developers to innovate by using the IP address of a given user to determine which language to use to display the user content and what product or service to serve in a given country.
Asset Tracking Using Referential API
The Referential API can be used as a comprehensive asset tracking data provider. To explain, one of the main capabilities of this API is its ability to determine, based on a given IP address the city of a user. Indeed, this feature can create an asset tracking application that can help transportation companies track the delivery of their product based on the IP address of the current location of a product. In addition, this API can be used to develop applications that can determine a user’s site based on their IP address. This capability is essential in helping companies create practical applications based on location and language.
Alternatives to the Referential API
RapidAPI offers a list of various location-based APIs. These APIs can be an alternative to the Referential API. The following is a list that includes some of these APIs:
- IP Geo Location: This API returns a comprehensive list of IP-related data. For instance, based on a given IP address, the country, city, latitude, longitude, and time zone will be returned detailing geographical information about that IP address.
- City Geo-Location Lookup: This API returns city-based information that is summarized as latitude, longitude, name, time zone, and country.
- Google Maps Geocoding: This API returns geocoding data based on latitude and longitude based on a given address. This API uses Google Maps capabilities that can take a simple address and converts it to geolocation on the map or vice versa.
- GeoDB Cities: This API returns cities information, country data, and regional information from a global database. Every data point can be extracted in multiple languages.
- World Geo Data: This API returns a searchable list of cities, countries, regions, and administrative divisions based on country and city in a detailed format.
Summary
The Referential API helps collect fine-tuned countries, states, cities, continents, languages, and time zones related information. The data provided by the Referential API can be displayed in more than 20 languages. This tutorial covers the Referential API using Python, PHP, Ruby, and JavaScript. In addition, this article covers the main benefits, users, alternatives, and endpoints of this API.
Leave a Reply