Geo-IP API at the edge

Create an API endpoint for fetching GeoIP data for the requesting browser, implemented 100% at the edge. The response should show your current approximate location, but no requests to any origin servers.


Use this solution in your VCL service (click RUN below to test this solution or clone it to make changes):


Use this solution in your Compute@Edge service:

  1. Rust
let client_ip = req
.ok_or_else(|| anyhow!("could not get client ip"))?;
let geo = geo_lookup(client_ip).ok_or_else(|| anyhow!("no geographic data available"))?;
let body = json!({
"as": {
"name": geo.as_name(),
"geo" : {
"client_ip": client_ip,
"country_name": geo.country_name(),
"gmt_offset:": geo.utc_offset().to_string(),