Authentication overview

RoadGoat Cities utilizes API keys to manage access to its geographic data services, including information on cities, states, and countries. This method provides a straightforward way for developers to authenticate their applications and control usage according to their subscription plan, which includes a free tier of 1,000 requests per month. An API key acts as a unique identifier and secret token that RoadGoat Cities uses to verify the identity of the calling application and authorize its requests against the API. Each key is associated with a specific user account, enabling RoadGoat Cities to track usage, enforce rate limits, and apply subscription-based access permissions.

The API key mechanism is a common authentication pattern for web services, especially those that primarily serve read-only data or whose access control requirements are met by identifying the application rather than individual end-users. While simpler than token-based systems like OAuth 2.0 for client-side applications, it necessitates careful handling to prevent unauthorized access and potential misuse of the API key, as outlined in the RoadGoat API documentation.

Supported authentication methods

RoadGoat Cities primarily supports API Key authentication. This method is integrated across its various APIs, including the Cities API, Countries API, and States API, ensuring a consistent authentication experience for all RoadGoat Cities core products.

API Key

RoadGoat Cities employs a single API key per user account to authenticate requests. This key is a unique string that developers include in each API request. The key identifies the calling application and verifies its authorization to access the requested resources. RoadGoat Cities's approach focuses on simplicity and ease of integration for developers building applications that require geographic data.

The table below summarizes the API key authentication method:

Method When to Use Security Level Notes
API Key All API interactions with RoadGoat Cities. Suitable for server-side applications, client-side applications with proper environmental variable management. Moderate Requires careful handling to prevent exposure. Directly links requests to your account.

Getting your credentials

To access the RoadGoat Cities API, you must first obtain an API key. This key serves as your credential for authenticating all requests. The process involves creating an account and generating the key through the RoadGoat account dashboard.

  1. Sign up for a RoadGoat account: Navigate to the RoadGoat homepage and sign up for a new account if you do not already have one. This will grant you access to the dashboard and the free tier, which includes 1,000 requests per month.
  2. Access the API Dashboard: After logging in, locate the API section or dashboard within your RoadGoat account interface. This is typically where API keys are managed.
  3. Generate your API Key: Within the API dashboard, there should be an option to generate or view your API key. RoadGoat Cities provides a single key for all API access. Copy this key, as it will be required for all authenticated requests. It is crucial to store this key securely and avoid hardcoding it directly into client-side code or public repositories.

RoadGoat Cities's documentation details the specific steps for managing your API keys, including regeneration options if a key is compromised. Always refer to the official documentation for the most up-to-date instructions.

Authenticated request example

Once you have obtained your API key, you can include it in your API requests. For RoadGoat Cities, the API key is typically passed as a header named X-RoadGoat-API-Key. This ensures the key is transmitted securely over HTTPS and is not part of the URL, which could be logged or exposed more easily.

Here's an example of an authenticated request using cURL to retrieve information about a city, as detailed in the RoadGoat Cities API reference:

curl -X GET \
  'https://api.roadgoat.com/api/v2/cities/search?query=london' \
  -H 'X-RoadGoat-API-Key: YOUR_API_KEY_HERE' \
  -H 'Accept: application/json'

Replace YOUR_API_KEY_HERE with the actual API key you obtained from your RoadGoat account dashboard. The Accept: application/json header is also included to specify the desired response format.

For programmatic access in various languages, your API key would be included in the request headers:

import requests

api_key = "YOUR_API_KEY_HERE"
headers = {
    "X-RoadGoat-API-Key": api_key,
    "Accept": "application/json"
}
url = "https://api.roadgoat.com/api/v2/cities/search?query=paris"

response = requests.get(url, headers=headers)
print(response.json())

This Python example demonstrates how to construct a request with the API key in the headers using the requests library.

Security best practices

Securing your RoadGoat Cities API key is critical to prevent unauthorized access to your account and API usage. Adhering to these best practices will help maintain the integrity of your applications and protect your subscription limits:

  • Do not embed API keys directly in client-side code: Exposing API keys in public client-side code (e.g., JavaScript in a web browser, mobile application bundles) makes them easily discoverable and exploitable. Instead, use a backend proxy or server-side component to make API calls, which can securely store and manage the API key.
  • Use environment variables for server-side applications: For server-side applications, store your API key as an environment variable rather than hardcoding it into your source code. This practice separates sensitive credentials from your codebase and prevents them from being committed to version control systems like Git. The Google Cloud documentation on securing API keys provides similar recommendations for managing credentials.
  • Restrict API key usage if possible: While RoadGoat Cities's API keys typically grant broad access, if the platform introduces features to restrict keys by IP address or HTTP referrer, utilize them. This adds a layer of security by limiting where and by whom your key can be used.
  • Implement HTTPS: Always ensure that all communications with the RoadGoat Cities API are conducted over HTTPS. This encrypts the data in transit, including your API key, protecting it from interception by malicious actors. RoadGoat Cities enforces HTTPS for all API endpoints.
  • Monitor API usage: Regularly review your API usage statistics in the RoadGoat dashboard. Unusual spikes in requests could indicate that your API key has been compromised. Promptly investigate any suspicious activity.
  • Rotate API keys periodically: Change your API key regularly, especially if there's any suspicion of compromise or after significant changes to your development team. Most API dashboards provide functionality to regenerate keys, invalidating the old one.
  • Secure your development environment: Ensure that your development machines and build pipelines are secure. Access to these environments could expose your API keys.