### cURL: Access Autocomplete API via Command Line
Source: https://context7.com/aviationedgeapi/autocomplete-api/llms.txt
This snippet provides examples of how to access the Aviation Edge Autocomplete API directly using cURL commands. It covers basic requests, requesting JSON output, and filtering results for partial matches. The `jq` command-line JSON processor is used for formatting and filtering output.
```bash
# Basic request for Berlin airports
curl -X GET "https://aviation-edge.com/v2/public/autocomplete?key=YOUR_API_KEY&city=berlin"
# Request with formatted output
curl -X GET "https://aviation-edge.com/v2/public/autocomplete?key=YOUR_API_KEY&city=london" \
-H "Accept: application/json" \
| jq '.'
# Search for partial matches (e.g., "ist")
curl -X GET "https://aviation-edge.com/v2/public/autocomplete?key=YOUR_API_KEY&city=ist" \
| jq '.[] | {airport: .nameAirport, iata: .codeIataAirport, country: .nameCountry}'
# Example response structure:
# [
# {
# "GMT": "1",
# "codeIataAirport": "SXF",
# "codeIataCity": "BER",
# "codeIcaoAirport": "EDDB",
# "codeIso2Country": "DE",
# "latitudeAirport": 52.370277,
# "longitudeAirport": 13.521388,
# "nameAirport": "Berlin-Schoenefeld",
# "nameCountry": "Germany",
# "phone": "",
# "timezone": "Europe/Berlin"
# }
# ]
```
--------------------------------
### Backend Autocomplete Search with Python Requests
Source: https://context7.com/aviationedgeapi/autocomplete-api/llms.txt
Provides a Python class for server-side integration with the Aviation Edge Autocomplete API, suitable for backend applications and data processing. It utilizes the 'requests' library to make HTTP GET requests and includes error handling for network issues and HTTP errors. The class allows searching for airports and optionally filtering by country.
```python
import requests
from typing import List, Dict, Optional
class AviationEdgeAutocomplete:
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = 'https://aviation-edge.com/v2/public/autocomplete'
def search_airports(self, city: str) -> Optional[List[Dict]]:
"""
Search for airports by city name or partial text.
Args:
city: City name or partial text to search
Returns:
List of airport dictionaries or None on error
"""
params = {
'key': self.api_key,
'city': city
}
try:
response = requests.get(self.base_url, params=params, timeout=10)
response.raise_for_status()
airports = response.json()
print(f"Found {len(airports)} airports matching '{city}'")
return airports
except requests.exceptions.HTTPError as e:
print(f"HTTP Error: {e.response.status_code}")
return None
except requests.exceptions.Timeout:
print("Request timed out")
return None
except requests.exceptions.RequestException as e:
print(f"Request failed: {str(e)}")
return None
def filter_by_country(self, city: str, country_code: str) -> List[Dict]:
"""Filter search results by country ISO code."""
airports = self.search_airports(city)
if not airports:
return []
return [
airport for airport in airports
if airport.get('codeIso2Country') == country_code
]
# Example usage
if __name__ == '__main__':
api = AviationEdgeAutocomplete('your_api_key_here')
# Basic search
results = api.search_airports('berlin')
if results:
for airport in results:
print(f"\nAirport: {airport['nameAirport']}")
print(f"IATA: {airport['codeIataAirport']}")
print(f"ICAO: {airport['codeIcaoAirport']}")
print(f"Country: {airport['nameCountry']}")
print(f"Coordinates: {airport['latitudeAirport']}, {airport['longitudeAirport']}")
print(f"Timezone: {airport['timezone']}")
# Filtered search
german_airports = api.filter_by_country('ist', 'DE')
print(f"\nFound {len(german_airports)} German airports with 'ist' in name")
# Expected output example:
# Found 2 airports matching 'berlin'
#
# Airport: Berlin-Schoenefeld
# IATA: SXF
# ICAO: EDDB
# Country: Germany
# Coordinates: 52.370277, 13.521388
# Timezone: Europe/Berlin
```
--------------------------------
### Frontend Autocomplete Search with JavaScript Fetch API
Source: https://context7.com/aviationedgeapi/autocomplete-api/llms.txt
Implements real-time airport autocomplete functionality in web applications using the browser's Fetch API. This class handles API requests, response parsing, and formatting results for display. It requires an API key and expects DOM elements for input and displaying results.
```javascript
class AirportAutocomplete {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = 'https://aviation-edge.com/v2/public/autocomplete';
}
async search(query) {
if (!query || query.length < 2) {
return [];
}
try {
const url = `${this.baseUrl}?key=${this.apiKey}&city=${encodeURIComponent(query)}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Autocomplete search failed:', error);
return [];
}
}
formatResult(airport) {
return {
label: `${airport.nameAirport} (${airport.codeIataAirport})`,
value: airport.codeIataAirport,
city: airport.codeIataCity,
country: airport.nameCountry,
coordinates: {
lat: airport.latitudeAirport,
lng: airport.longitudeAirport
},
timezone: airport.timezone
};
}
}
// Usage example
const autocomplete = new AirportAutocomplete('your_api_key_here');
document.getElementById('airport-input').addEventListener('input', async (e) => {
const query = e.target.value;
const results = await autocomplete.search(query);
const formatted = results.map(airport => autocomplete.formatResult(airport));
// Display results
const dropdown = document.getElementById('airport-dropdown');
dropdown.innerHTML = formatted.map(result =>
`
${result.label} - ${result.country}
`
).join('');
});
// Expected formatted output:
// {
// label: "Berlin-Schoenefeld (SXF)",
// value: "SXF",
// city: "BER",
// country: "Germany",
// coordinates: { lat: 52.370277, lng: 13.521388 },
// timezone: "Europe/Berlin"
// }
```
--------------------------------
### Fetch Airport Data by City using Axios
Source: https://github.com/aviationedgeapi/autocomplete-api/blob/main/README.md
This JavaScript code snippet demonstrates how to fetch airport and city autocomplete data using the Axios library. It requires an API key and a city name as input, and it returns the data from the Aviation Edge Autocomplete API. Error handling is included for network issues or failed requests.
```javascript
const axios = require('axios');
const API_KEY = 'api-key'; // Replace with your actual API key
const BASE_URL = 'https://aviation-edge.com/v2/public/autocomplete';
async function getAirportsByCity(city) {
try {
const response = await axios.get(BASE_URL, {
params: {
key: API_KEY,
city: city
}
});
if (response.status === 200 && response.data) {
return response.data;
} else {
throw new Error(`Failed to retrieve data. Status code: ${response.status}`);
}
} catch (error) {
console.error(`Error fetching airports for city ${city}:`, error);
}
}
// Example usage:
getAirportsByCity('berlin').then(data => {
console.log(data);
});
```
--------------------------------
### JavaScript: Fetch Airport Autocomplete Data with Axios
Source: https://context7.com/aviationedgeapi/autocomplete-api/llms.txt
This snippet demonstrates how to use the axios library in JavaScript to call the Aviation Edge Autocomplete API. It retrieves airport data based on a city name, handles API responses, and logs detailed airport information including names, codes, locations, and timezones. Error handling for API requests is also included.
```javascript
const axios = require('axios');
const API_KEY = 'your_api_key_here';
const BASE_URL = 'https://aviation-edge.com/v2/public/autocomplete';
async function getAirportsByCity(city) {
try {
const response = await axios.get(BASE_URL, {
params: {
key: API_KEY,
city: city
}
});
if (response.status === 200 && response.data) {
console.log(`Found ${response.data.length} airports matching: ${city}`);
response.data.forEach(airport => {
console.log(`${airport.nameAirport} (${airport.codeIataAirport})`);
console.log(` Location: ${airport.nameCountry}`);
console.log(` Coordinates: ${airport.latitudeAirport}, ${airport.longitudeAirport}`);
console.log(` Timezone: ${airport.timezone}`);
});
return response.data;
} else {
throw new Error(`Failed to retrieve data. Status code: ${response.status}`);
}
} catch (error) {
if (error.response) {
console.error(`API Error: ${error.response.status} - ${error.response.statusText}`);
} else if (error.request) {
console.error('No response received from API');
} else {
console.error(`Error: ${error.message}`);
}
return null;
}
}
// Example usage
getAirportsByCity('berlin').then(data => {
if (data) {
console.log('Successfully retrieved airport data');
}
});
// Expected output:
// {
// "GMT": "1",
// "codeIataAirport": "SXF",
// "codeIataCity": "BER",
// "codeIcaoAirport": "EDDB",
// "codeIso2Country": "DE",
// "latitudeAirport": 52.370277,
// "longitudeAirport": 13.521388,
// "nameAirport": "Berlin-Schoenefeld",
// "nameCountry": "Germany",
// "phone": "",
// "timezone": "Europe/Berlin"
// }
```
--------------------------------
### Autocomplete API - Airport and City Search
Source: https://context7.com/aviationedgeapi/autocomplete-api/llms.txt
This section details the response structure and field descriptions for the Aviation Edge Autocomplete API.
```APIDOC
## Autocomplete API - Airport and City Search
### Description
Provides autocomplete suggestions for airports and cities based on user input. The API returns a structured response containing detailed information about matching locations.
### Method
GET
### Endpoint
`/aviationedgeapi/autocomplete-api`
### Query Parameters
* **query** (string) - Required - The search query string for airport or city names.
* **limit** (integer) - Optional - The maximum number of results to return.
### Request Example
```
GET /aviationedgeapi/autocomplete-api?query=ber&limit=5
```
### Response
#### Success Response (200)
- **GMT** (string) - GMT offset as string
- **codeIataAirport** (string) - 3-letter IATA airport code
- **codeIataCity** (string) - 3-letter IATA city code
- **codeIcaoAirport** (string) - 4-letter ICAO airport code
- **codeIso2Country** (string) - 2-letter ISO country code
- **latitudeAirport** (number) - Decimal latitude coordinate
- **longitudeAirport** (number) - Decimal longitude coordinate
- **nameAirport** (string) - Full airport name
- **nameCountry** (string) - Country name
- **phone** (string) - Airport phone number (may be empty)
- **timezone** (string) - IANA timezone identifier
#### Response Example
```json
[
{
"GMT": "1",
"codeIataAirport": "SXF",
"codeIataCity": "BER",
"codeIcaoAirport": "EDDB",
"codeIso2Country": "DE",
"latitudeAirport": 52.370277,
"longitudeAirport": 13.521388,
"nameAirport": "Berlin-Schoenefeld",
"nameCountry": "Germany",
"phone": "",
"timezone": "Europe/Berlin"
}
]
```
```
--------------------------------
### Airport/City Autocomplete Search
Source: https://context7.com/aviationedgeapi/autocomplete-api/llms.txt
This endpoint searches for airports and cities based on partial text input, returning comprehensive airport information including codes, coordinates, and location details.
```APIDOC
## GET /v2/public/autocomplete
### Description
Searches for airports and cities based on partial text input. Returns comprehensive airport information including codes, coordinates, and location details. The matching algorithm finds occurrences of the search string anywhere within airport or city names.
### Method
GET
### Endpoint
`https://aviation-edge.com/v2/public/autocomplete`
### Parameters
#### Query Parameters
- **key** (string) - Required - Your API key.
- **city** (string) - Required - The partial text to search for (e.g., 'berlin', 'ist').
### Request Example
```bash
curl -X GET "https://aviation-edge.com/v2/public/autocomplete?key=YOUR_API_KEY&city=berlin"
```
### Response
#### Success Response (200)
Returns an array of airport objects matching the search query.
- **GMT** (string) - GMT offset.
- **codeIataAirport** (string) - IATA airport code.
- **codeIataCity** (string) - IATA city code.
- **codeIcaoAirport** (string) - ICAO airport code.
- **codeIso2Country** (string) - ISO 3166-1 alpha-2 country code.
- **latitudeAirport** (number) - Airport latitude.
- **longitudeAirport** (number) - Airport longitude.
- **nameAirport** (string) - Name of the airport.
- **nameCountry** (string) - Name of the country.
- **phone** (string) - Airport phone number (if available).
- **timezone** (string) - Airport timezone.
#### Response Example
```json
[
{
"GMT": "1",
"codeIataAirport": "SXF",
"codeIataCity": "BER",
"codeIcaoAirport": "EDDB",
"codeIso2Country": "DE",
"latitudeAirport": 52.370277,
"longitudeAirport": 13.521388,
"nameAirport": "Berlin-Schoenefeld",
"nameCountry": "Germany",
"phone": "",
"timezone": "Europe/Berlin"
}
]
```
```
--------------------------------
### Autocomplete API - Search by City
Source: https://github.com/aviationedgeapi/autocomplete-api/blob/main/README.md
This endpoint allows you to retrieve a list of airports and cities that match a given city name. It's useful for providing autocomplete suggestions in search fields.
```APIDOC
## GET /v2/public/autocomplete
### Description
Retrieves a list of airports and cities based on the provided city name. The API returns locations where the submitted letters appear anywhere in the name.
### Method
GET
### Endpoint
`https://aviation-edge.com/v2/public/autocomplete`
### Parameters
#### Query Parameters
- **key** (string) - Required - Your unique API key.
- **city** (string) - Required - The city name or letters to search for.
### Request Example
```
GET https://aviation-edge.com/v2/public/autocomplete?key=YOUR_API_KEY&city=berlin
```
### Response
#### Success Response (200)
- **GMT** (string) - Greenwich Mean Time offset.
- **codeIataAirport** (string) - IATA code for the airport.
- **codeIataCity** (string) - IATA code for the city.
- **codeIcaoAirport** (string) - ICAO code for the airport.
- **codeIso2Country** (string) - Two-letter country code.
- **latitudeAirport** (number) - Latitude of the airport.
- **longitudeAirport** (number) - Longitude of the airport.
- **nameAirport** (string) - Name of the airport.
- **nameCountry** (string) - Name of the country.
- **phone** (string) - Phone number (if available).
- **timezone** (string) - Timezone of the airport's location.
#### Response Example
```json
{
"GMT": "1",
"codeIataAirport": "SXF",
"codeIataCity": "BER",
"codeIcaoAirport": "EDDB",
"codeIso2Country": "DE",
"latitudeAirport": 52.370277,
"longitudeAirport": 13.521388,
"nameAirport": "Berlin-Schoenefeld",
"nameCountry": "Germany",
"phone": "",
"timezone": "Europe/Berlin"
}
```
### Useful Example Codes
1. Fetching the data using Axios:
```javascript
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY'; // Replace with your actual API key
const BASE_URL = 'https://aviation-edge.com/v2/public/autocomplete';
async function getAirportsByCity(city) {
try {
const response = await axios.get(BASE_URL, {
params: {
key: API_KEY,
city: city
}
});
if (response.status === 200 && response.data) {
return response.data;
} else {
throw new Error(`Failed to retrieve data. Status code: ${response.status}`);
}
} catch (error) {
console.error(`Error fetching airports for city ${city}:`, error);
}
}
// Example usage:
getAirportsByCity('berlin').then(data => {
console.log(data);
});
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.