使用 IP2GeoVapor 获取 JSON 格式的任何 IP 地址的地理位置信息
IP2土蒸气
IP2Geo是一个Vapor API,可让您轻松获取IP地址的地理信息。IP-API 服务默认使用 HTTP,但此包使用 HTTPS 来确保安全连接。
用法
要获取 IP 地址的地理信息,您可以向其中发出 GET 请求,其中 :ipAddress 是要获取信息的 IP 地址。响应将采用 的形式。/json/:ipAddress
JSON
{
"status": true,
"country": "United States",
"countryCode": "US",
"regionName": "California",
"city": "Mountain View",
"query": "8.8.8.8",
"currency": "USD"
}
响应
响应将是一个包含以下信息的 JSON 对象:
status
:布尔值,如果请求成功,则为“true”,否则为“false”。currency
:字符串,IP 地址所在国家/地区使用的货币。country
:字符串,IP 地址所在国家/地区的名称。countryCode
:字符串,IP 地址的 2 个字母的国家/地区代码。regionName
:字符串,IP 地址的区域名称。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 a response.
400 Bad Request
Customization
Response Format
The response format can be changed by specifying the parameter in the function. The available options are , , and .responseType
getIpApiResponse(_:for:responseType:)
.json
.xml
.csv
.newline
Work In Progress
- 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
Error Handling
In case of any error, the package throws Abort error with status 400 Bad Request
Author
License
IP2GeoVapor is released under the MIT license.