A few months ago I needed to write some code to interact with the IP API service to fetch geolocation data for certain conditions within the application.
The code I needed to implement was only a single call to a single endpoint on the API, but that evening I decided to write an API wrapper for it in CFML anyway, which was released as open source that very night.
Instantiation of the component is simple.
Grab an API key from the IP API service and include it within the
init() constructor call.
Not all plans on the service support
HTTPS, so if you don’t have it, you will need to pass the
HTTP endpoint into the constructor method too, using the
To grab a data structure for a given IP address, simply call the
ipLookup() method, passing in the IP address to query:
If your subscription plan includes bulk IP lookups, you can optionally send in a comma-separated list of IP addresses.
You can also perform an IP lookup on any IP address that makes the call to the API, so if you want to test it out easily and verify information for your IP,
simply call the
originIPLookup() method without sending through any parameters.
As you can see, the response contains a lot of really useful information:
Responses for all requests can be either
json (default), which is configurable as an argument for each method.
You can find the project on my Github repository here