IP2Geo is a Vapor API that allows you to easily fetch geographical information of an IP address. The IP-API service uses HTTP by default, but this package uses HTTPS to ensure a secure connection.
To get the geographical information of an IP address, you can make a GET request to /json/:ipAddress
where :ipAddress is the IP address for which you want to get the information. The response will be in the form of JSON
.
{
"status": true,
"country": "United States",
"countryCode": "US",
"regionName": "California",
"city": "Mountain View",
"query": "8.8.8.8",
"currency": "USD"
}
The response will be a JSON object containing the following information:
status
: Boolean, "true" if the request was successful, "false" otherwise.currency
: String, the currency used in the country of the IP address.country
: String, the name of the country of the IP address.countryCode
: String, the 2-letter country code of the IP address.regionName
: String, the name of the region of the IP address.city
: String, the name of the city of the IP address.query
: String, the IP address used in the request.
Note
This endpoint is limited to 45 requests / minute
Warning
If the IP address is not valid, the server will return a400 Bad Request
response.
If you make a GET request to /myip, the server will return your IP address as a string. For example, if your IP address is 8.8.8.8, the response will be:
{
"status":true,
"ip":"183.82.206.135"
}
The response format can be changed by specifying the responseType
parameter in the getIpApiResponse(_:for:responseType:)
function. The available options are .json
, .xml
, .csv
and .newline
.
- Adding load balancer
- Adding support for csv, xml, newline
- Adding support for IPv6 addresses
- Adding option to specify the fields to be returned in the IP-API response
In case of any error, the package throws Abort error with status 400 Bad Request
For information on how to deploy IP2GeoVapor to a VPS, see this Medium article.
IP2GeoVapor is released under the MIT license.