IPRout

Go IP Geolocation API Example

Use Go net/http to send your IPRout key in the Authorization header, apply a 10-second timeout, reject non-success HTTP statuses, and parse the JSON response. Keep IPROUT_API_KEY in the server environment rather than source code or a browser bundle.

Last updated August 10, 2026

How do I call IPRout with Go?

This example looks up 8.8.8.8 unless the client example uses /ip to demonstrate caller lookup. Replace only the route when switching modes.

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "https://api.iprout.com/ip/8.8.8.8", nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("IPROUT_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil { log.Fatal(err) }
defer res.Body.Close()
if res.StatusCode >= 400 { log.Fatalf("IPRout HTTP %d", res.StatusCode) }

How do I look up the caller instead?

Keep the headers and error handling unchanged, but request https://api.iprout.com/ip with no address after /ip.

What does production code need?

Keep the key server-side, use a finite timeout, inspect HTTP status before decoding success data, and handle 401, 422, 429, and transient 500 responses.

  • Read IPROUT_API_KEY from a secret environment
  • Do not retry 401 or 422 automatically
  • Use bounded backoff for transient server or network failures