// v1 · IP Geolocation & Security API

Integrating with a backend - client IP address

While integrating with a server back end, you will need to determine the visitor's public IP address so that it may be passed to the Fastah API.

The client's public IP address is obtained by inspecting the incoming HTTP request object or context - see your language's HTTP server handler API documentation.

Determine the public IP address

  1. Inspect theX-Forwarded-For header - if present, extract the left-most value from the comma-separated list of IPs if it's present.
text
X-Forwarded-For: 2001:db8:85a3:8d3:1319:8a2e:370:7348

X-Forwarded-For: 203.0.113.195

X-Forwarded-For: 203.0.113.195, 70.41.3.18, 150.172.238.178
  1. If the X-Forwarded-For header is absent, simply use the remote IP address with any colons (":") removed - that is split the host and port and use only the host value as the client IP address.

Steps 1 and 2 above are demonstrated below in a Go programming language snippet.

go
// Use the server handler's object to inspect remote IP address
clientIP := params.HTTPRequest.RemoteAddr
if strings.Contains(clientIP, ":") { // host:port splitting
    if splitIP, _, serr := net.SplitHostPort(clientIP); serr == nil {
		  clientIP = splitIP
		}
}
// Extract X-Forwarded-For imformation if present - and use it
fwdList := params.HTTPRequest.Header.Get("X-Forwarded-For")
if fwdList != "" {
    clientIP = fwdList
		// Extract left-most entry in the comma-seperated list
		leftmost := strings.Split(fwdList, ",")
		if len(leftmost) > 0 {
          // 
					clientIP = leftmost[0] 
		}
}
clientIP = strings.TrimSpace(clientIP)

Send the request

Simply append the client IP address as a string to the base URL, append the API key as the Fastah-Key HTTP header, and send the request.

go
url := 'https://ep.api.getfastah.com/whereis/v1/json/' + clientIP

Performance tips - back end

Reuse the same HTTP client for calls to the Fastah API end-point, so your HTTP connection doesn't have to be re-established every time.
It's highly recommended to enable HTTP/2 support in the client to minimize API latency across all requests, and request+response throughput is maximized between your client and Fastah's API systems.

Need More Help?

Drop us a line at support@getfastah.com with any questions, bug reports, or training requests, or if you want to chat!

For Postman users

If you use the Postman API development tool, use the button below to open the collection in your workspace.

Run in Postman