The Geolocation component is an endpoint microservice that provides real-time geolocation data based on the user’s IP address. This lightweight HTTP service runs at the edge, offering fast and accurate location information without requiring additional backend infrastructure.

What is the Geolocation Component?

The Geolocation component is an endpoint component that:

  • Responds to HTTP requests with geolocation data
  • Provides continent, country, region, city, and IP information
  • Runs at the edge for optimal performance
  • Returns JSON responses with CORS support
  • Requires no additional backend infrastructure

Getting Started

To integrate the Geolocation component into your Edgee project:

  1. Open the Edgee console and navigate to your project’s Components.
  2. Select “Add a component” and choose edgee/geolocation from the list of available components.
  3. Configure the endpoint path pattern (e.g., /apigeo or /geolocation).
  4. Click Save to deploy the component.

Once configured, the component will respond to requests at your specified path with geolocation data.

API Response

The component returns a JSON response with the following structure:

{
  "continent": "NA",
  "country_name": "united states",
  "country_code": "US",
  "region": "TX",
  "city": "huntsville",
  "ip": "203.0.113.1"
}

Usage Examples

JavaScript Fetch Request

fetch('/apigeo')
  .then(response => response.json())
  .then(data => {
    console.log('User location:', data.city, data.country_name);
  });

cURL Request

curl https://yourdomain.com/api/geo

Configuration

Path Pattern

Configure the URL path where the geolocation service will be available. For example:

  • /apigeo - Responds to requests at yourdomain.com/apigeo
  • /geolocation - Responds to requests at yourdomain.com/geolocation
  • /location - Responds to requests at yourdomain.com/location

Key Features

  • Real-time Data: Provides current geolocation based on IP address
  • Edge Performance: Runs at the edge for minimal latency
  • CORS Support: Includes proper CORS headers for cross-origin requests
  • No Cache: Returns fresh data with no-store cache control
  • JSON Format: Clean, structured JSON responses
  • Serverless: No backend infrastructure required

Use Cases

The Geolocation component is perfect for:

  • Content Localization: Serve region-specific content based on user location
  • Analytics: Track user geographic distribution
  • Compliance: Determine applicable privacy regulations based on location
  • Personalization: Customize user experience based on geographic data
  • Security: Implement location-based access controls

Response Headers

The component automatically sets the following headers:

  • Content-Type: application/json
  • Cache-Control: private, no-store
  • Access-Control-Allow-Origin: *

Performance

As an endpoint component running at the edge, the Geolocation service provides:

  • Sub-10ms response times in most cases
  • Global availability through Edgee’s edge network
  • Automatic scaling based on demand
  • Zero maintenance - no servers to manage