Determines the location and other details of an IP address.
1
type Abstractapi = {
2
apiKey: string
3
}
4
5
export async function main(resource: Abstractapi, ipAddress?: string) {
6
const queryParams = new URLSearchParams({
7
api_key: resource.apiKey
8
})
9
10
if (ipAddress) {
11
queryParams.append('ip_address', ipAddress)
12
13
14
const endpoint = `https://ipgeolocation.abstractapi.com/v1?${queryParams.toString()}`
15
16
const response = await fetch(endpoint, {
17
method: 'GET'
18
19
20
if (!response.ok) {
21
throw new Error(`HTTP error! status: ${response.status}`)
22
23
24
const data = await response.json()
25
26
return data
27
28