The Airport API provides a RESTful interface to query airport data, including details like airport type, location, and whether it is used for armed forces.
- Query airports by name, city, country, and type.
- Filter results for airports used by armed forces.
- Paginated responses for large datasets.
- Clone the repository:
git clone https://github.com/hellosatyajit/airport.git cd airport - Install dependencies:
bun install
The data is sourced from datasets/airport-codes. Follow these steps to set up the database and deploy the project:
-
Create the Database
wrangler d1 create airports_db
-
Add the
database_idtowrangler.tomlwrangler secret put DB_ID echo "DB_ID=your-database-id" >> .env
-
Execute the Schema
wrangler d1 execute airports_db --file=./schema.sql
-
Feed Data
bun feed
-
Import Additional Data
wrangler d1 execute airports_db --file=./import_data.sql
-
Deploy the Project
wrangler deploy
Start the server in development mode:
wrangler dev src/index.tsThe server will be available at http://127.0.0.1:8787 by default.
Deploy the workers to Cloudflare
wrangler deployGET /
- Description: Displays a welcome message.
- Response:
"Welcome to Airport API"
GET /search
-
Description: Search for airports based on query parameters.
-
Query Parameters:
Parameter Type Description q string Search term for airport name or municipality. name string Filter by airport name. city string Filter by municipality. type enum Filter by type: airport,heliport,large_airport,medium_airport,small_airport.country string 2-letter ISO country code. armforced enum Filter by armed forces usage: trueorfalse.ident string Filter by airport identifier. iata string Filter by IATA code. limit number Number of results to return (default: 10). offset number Offset for pagination (default: 0). -
Example Request:
GET /search?q=Ahmedabad
-
Example Response:
{ "success": true, "length": 1, "data": [ { "id": 76890, "ident": "VAAH", "type": "medium_airport", "name": "Sardar Vallabh Bhai Patel International Airport", "elevation_ft": 189, "continent": "AS", "iso_country": "IN", "iso_region": "IN-GJ", "municipality": "Ahmedabad", "gps_code": "VAAH", "iata_code": "AMD", "local_code": "", "latitude": 23.0772, "longitude": 72.634697, "is_armforced": 0 } ] }
If invalid query parameters are provided, the API returns a 400 status code with an error message:
{
"success": false,
"message": "Invalid query parameters"
}In case of server errors, a 500 status code is returned:
{
"success": false,
"message": "An unexpected error occurred. Please try again later."
}The airports table contains the following fields:
| Field | Type | Description |
|---|---|---|
| id | INTEGER | Autoincrement primary key for each record. |
| ident | TEXT | Unique identifier for the airport. |
| type | TEXT | Type of the airport. |
| name | TEXT | Name of the airport. |
| elevation_ft | INTEGER | Elevation in feet. |
| continent | TEXT | Continent code. |
| iso_country | TEXT | ISO country code. |
| iso_region | TEXT | ISO region code. |
| municipality | TEXT | Municipality/city name. |
| gps_code | TEXT | GPS code of the airport. |
| iata_code | TEXT | IATA code of the airport. |
| local_code | TEXT | Local code of the airport. |
| latitude | REAL | Latitude coordinate. |
| longitude | REAL | Longitude coordinate. |
| is_armforced | BOOLEAN | Whether the airport is for armed forces. |
Feel free to open issues or submit pull requests for improvements or bug fixes.
Data sourced from datasets/airport-codes.