@sharpapi/sharpapi-node-airports 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +217 -291
- package/package.json +1 -1
- package/src/CLAUDE.md +7 -0
- package/src/SharpApiAirportsService.js +63 -60
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
# Airports Database & Flight Duration
|
|
3
|
+
# Airports Database & Flight Duration API for Node.js
|
|
4
4
|
|
|
5
|
-
## ✈️ Access
|
|
5
|
+
## ✈️ Access 30k+ airports and calculate flight durations — powered by SharpAPI.
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/@sharpapi/sharpapi-node-airports)
|
|
8
8
|
[](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
|
|
9
9
|
|
|
10
|
-
**SharpAPI Airports Database** provides access to nearly 30,000 airports worldwide with
|
|
10
|
+
**SharpAPI Airports Database** provides access to nearly 30,000 airports worldwide with detailed information including ICAO, IATA, LID codes, and geographical data. Also calculates precise flight durations between airports.
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
@@ -17,9 +17,11 @@
|
|
|
17
17
|
2. [Installation](#installation)
|
|
18
18
|
3. [Usage](#usage)
|
|
19
19
|
4. [API Documentation](#api-documentation)
|
|
20
|
-
5. [
|
|
21
|
-
6. [
|
|
22
|
-
7. [
|
|
20
|
+
5. [Examples](#examples)
|
|
21
|
+
6. [Use Cases](#use-cases)
|
|
22
|
+
7. [API Endpoints](#api-endpoints)
|
|
23
|
+
8. [Related Packages](#related-packages)
|
|
24
|
+
9. [License](#license)
|
|
23
25
|
|
|
24
26
|
---
|
|
25
27
|
|
|
@@ -34,9 +36,9 @@
|
|
|
34
36
|
|
|
35
37
|
### Step 1. Install the package via npm:
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
\`\`\`bash
|
|
38
40
|
npm install @sharpapi/sharpapi-node-airports
|
|
39
|
-
|
|
41
|
+
\`\`\`
|
|
40
42
|
|
|
41
43
|
### Step 2. Get your API key
|
|
42
44
|
|
|
@@ -46,167 +48,147 @@ Visit [SharpAPI.com](https://sharpapi.com/) to get your API key.
|
|
|
46
48
|
|
|
47
49
|
## Usage
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
\`\`\`javascript
|
|
50
52
|
const { SharpApiAirportsService } = require('@sharpapi/sharpapi-node-airports');
|
|
51
53
|
|
|
52
|
-
const apiKey = process.env.SHARP_API_KEY;
|
|
54
|
+
const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
|
|
53
55
|
const service = new SharpApiAirportsService(apiKey);
|
|
54
56
|
|
|
55
57
|
async function searchAirports() {
|
|
56
58
|
try {
|
|
57
|
-
//
|
|
59
|
+
// Get airports in a specific country
|
|
58
60
|
const airports = await service.getAirports({
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
console.log(`Found ${airports.data.length} airports:`);
|
|
65
|
-
airports.data.forEach(airport => {
|
|
66
|
-
console.log(`${airport.name} (${airport.iata}) - ${airport.city}, ${airport.country}`);
|
|
61
|
+
country: 'US',
|
|
62
|
+
iata_assigned: true,
|
|
63
|
+
per_page: 10
|
|
67
64
|
});
|
|
68
65
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
console.log('\nJFK Airport:', jfk);
|
|
72
|
-
|
|
73
|
-
// Calculate flight duration
|
|
74
|
-
const duration = await service.calculateFlightDuration('JFK', 'LAX');
|
|
75
|
-
console.log('\nFlight JFK → LAX:', duration);
|
|
66
|
+
console.log('Found airports:', airports.data);
|
|
67
|
+
console.log('Total:', airports.meta.total);
|
|
76
68
|
} catch (error) {
|
|
77
69
|
console.error('Error:', error.message);
|
|
78
70
|
}
|
|
79
71
|
}
|
|
80
72
|
|
|
81
73
|
searchAirports();
|
|
82
|
-
|
|
74
|
+
\`\`\`
|
|
83
75
|
|
|
84
76
|
---
|
|
85
77
|
|
|
86
78
|
## API Documentation
|
|
87
79
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
#### `getAirports(filters?: object): Promise<object>`
|
|
80
|
+
All endpoints are **synchronous** and return data immediately (no polling required).
|
|
91
81
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
**Filters:**
|
|
95
|
-
- `per_page` (number): Results per page (max 100, default: 25)
|
|
96
|
-
- `iata_assigned` (boolean): Only airports with IATA codes
|
|
97
|
-
- `icao_assigned` (boolean): Only airports with ICAO codes
|
|
98
|
-
- `lid_assigned` (boolean): Only airports with LID codes
|
|
99
|
-
- `country` (string): Filter by 2-letter country code
|
|
100
|
-
- `timezone` (string): Filter by timezone
|
|
101
|
-
- `name` (string): Filter by airport name (partial match)
|
|
102
|
-
- `city` (string): Filter by city name (partial match)
|
|
103
|
-
|
|
104
|
-
**Returns:**
|
|
105
|
-
- Paginated list of airports with metadata
|
|
82
|
+
### Methods
|
|
106
83
|
|
|
107
|
-
#### `
|
|
84
|
+
#### `getAirports(filters)`
|
|
108
85
|
|
|
109
|
-
Get
|
|
86
|
+
Get a paginated list of airports with optional filters.
|
|
110
87
|
|
|
111
88
|
**Parameters:**
|
|
112
|
-
- `
|
|
89
|
+
- `filters` (object, optional):
|
|
90
|
+
- `per_page` (number, optional): Results per page (max 100, default 25)
|
|
91
|
+
- `iata_assigned` (boolean, optional): Filter for airports with IATA codes
|
|
92
|
+
- `icao_assigned` (boolean, optional): Filter for airports with ICAO codes
|
|
93
|
+
- `lid_assigned` (boolean, optional): Filter for airports with LID codes
|
|
94
|
+
- `country` (string, optional): Filter by 2-letter country code (e.g., 'US')
|
|
95
|
+
- `timezone` (string, optional): Filter by timezone (e.g., 'America/New_York')
|
|
96
|
+
- `name` (string, optional): Filter by airport name (partial match)
|
|
97
|
+
- `city` (string, optional): Filter by city name (partial match)
|
|
98
|
+
|
|
99
|
+
**Returns:** Promise<object> - Paginated list with data, links, and meta information
|
|
100
|
+
|
|
101
|
+
**Example:**
|
|
102
|
+
\`\`\`javascript
|
|
103
|
+
const airports = await service.getAirports({
|
|
104
|
+
country: 'GB',
|
|
105
|
+
iata_assigned: true,
|
|
106
|
+
per_page: 50
|
|
107
|
+
});
|
|
108
|
+
\`\`\`
|
|
113
109
|
|
|
114
|
-
#### `
|
|
110
|
+
#### `getAirportByUuid(uuid)`
|
|
115
111
|
|
|
116
|
-
Get airport information by
|
|
112
|
+
Get detailed airport information by UUID.
|
|
117
113
|
|
|
118
114
|
**Parameters:**
|
|
119
|
-
- `
|
|
115
|
+
- `uuid` (string, required): Airport UUID
|
|
120
116
|
|
|
121
|
-
|
|
117
|
+
**Returns:** Promise<object> - Airport details
|
|
122
118
|
|
|
123
|
-
|
|
119
|
+
**Example:**
|
|
120
|
+
\`\`\`javascript
|
|
121
|
+
const airport = await service.getAirportByUuid('1ef266de-5a6c-67d6-86a1-06bb2780ed98');
|
|
122
|
+
\`\`\`
|
|
124
123
|
|
|
125
|
-
#### `
|
|
124
|
+
#### `getAirportByIata(iataCode)`
|
|
126
125
|
|
|
127
|
-
|
|
126
|
+
Get airport information by IATA code.
|
|
128
127
|
|
|
129
128
|
**Parameters:**
|
|
130
|
-
- `
|
|
131
|
-
- `longitude` (number): Longitude coordinate
|
|
132
|
-
- `radius` (number, optional): Search radius in kilometers (default: 100)
|
|
133
|
-
- `limit` (number, optional): Maximum results (default: 10)
|
|
129
|
+
- `iataCode` (string, required): IATA airport code (e.g., 'LAX', 'JFK', 'LHR')
|
|
134
130
|
|
|
135
|
-
|
|
131
|
+
**Returns:** Promise<object> - Airport details
|
|
136
132
|
|
|
137
|
-
|
|
133
|
+
**Example:**
|
|
134
|
+
\`\`\`javascript
|
|
135
|
+
const airport = await service.getAirportByIata('LAX');
|
|
136
|
+
console.log(airport.name); // "Los Angeles International Airport"
|
|
137
|
+
\`\`\`
|
|
138
|
+
|
|
139
|
+
#### `getAirportByIcao(icaoCode)`
|
|
140
|
+
|
|
141
|
+
Get airport information by ICAO code.
|
|
138
142
|
|
|
139
143
|
**Parameters:**
|
|
140
|
-
- `
|
|
141
|
-
- `toIata` (string): Arrival airport IATA code
|
|
144
|
+
- `icaoCode` (string, required): ICAO airport code (e.g., 'KLAX', 'KJFK', 'EGLL')
|
|
142
145
|
|
|
143
|
-
|
|
146
|
+
**Returns:** Promise<object> - Airport details
|
|
144
147
|
|
|
145
|
-
|
|
148
|
+
**Example:**
|
|
149
|
+
\`\`\`javascript
|
|
150
|
+
const airport = await service.getAirportByIcao('KLAX');
|
|
151
|
+
\`\`\`
|
|
146
152
|
|
|
147
|
-
#### `
|
|
153
|
+
#### `getAirportByLid(lidCode)`
|
|
148
154
|
|
|
149
|
-
Get
|
|
155
|
+
Get airport information by LID code.
|
|
150
156
|
|
|
151
|
-
|
|
157
|
+
**Parameters:**
|
|
158
|
+
- `lidCode` (string, required): LID airport code
|
|
152
159
|
|
|
153
|
-
|
|
160
|
+
**Returns:** Promise<object> - Airport details
|
|
154
161
|
|
|
155
|
-
|
|
162
|
+
**Example:**
|
|
163
|
+
\`\`\`javascript
|
|
164
|
+
const airport = await service.getAirportByLid('00AA');
|
|
165
|
+
\`\`\`
|
|
156
166
|
|
|
157
|
-
|
|
158
|
-
{
|
|
159
|
-
"data": [
|
|
160
|
-
{
|
|
161
|
-
"id": "1ef266de-5a6c-67d6-86a1-06bb2780ed98",
|
|
162
|
-
"icao": "KJFK",
|
|
163
|
-
"iata": "JFK",
|
|
164
|
-
"lid": "",
|
|
165
|
-
"name": "John F Kennedy International Airport",
|
|
166
|
-
"city": "New York",
|
|
167
|
-
"subdivision": "New York",
|
|
168
|
-
"country": "US",
|
|
169
|
-
"timezone": "America/New_York",
|
|
170
|
-
"elevation": 13,
|
|
171
|
-
"latitude": 40.6398,
|
|
172
|
-
"longitude": -73.7789
|
|
173
|
-
}
|
|
174
|
-
],
|
|
175
|
-
"links": {
|
|
176
|
-
"first": "https://sharpapi.com/api/v1/airports?page=1",
|
|
177
|
-
"last": "https://sharpapi.com/api/v1/airports?page=1128",
|
|
178
|
-
"prev": null,
|
|
179
|
-
"next": "https://sharpapi.com/api/v1/airports?page=2"
|
|
180
|
-
},
|
|
181
|
-
"meta": {
|
|
182
|
-
"current_page": 1,
|
|
183
|
-
"from": 1,
|
|
184
|
-
"last_page": 1128,
|
|
185
|
-
"per_page": 25,
|
|
186
|
-
"to": 25,
|
|
187
|
-
"total": 28186
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
```
|
|
167
|
+
#### `calculateFlightDuration(...)`
|
|
191
168
|
|
|
192
|
-
|
|
169
|
+
Calculate flight duration between two airports.
|
|
193
170
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
171
|
+
**Parameters:**
|
|
172
|
+
- `departureCodeType` (string, required): 'iata', 'icao', or 'lid'
|
|
173
|
+
- `departureCode` (string, required): Departure airport code
|
|
174
|
+
- `departureDate` (string, required): Departure date in YYYY-MM-DD format
|
|
175
|
+
- `departureTime` (string, required): Departure time in HH:MM format (24-hour)
|
|
176
|
+
- `arrivalCodeType` (string, required): 'iata', 'icao', or 'lid'
|
|
177
|
+
- `arrivalCode` (string, required): Arrival airport code
|
|
178
|
+
- `arrivalDate` (string, required): Arrival date in YYYY-MM-DD format
|
|
179
|
+
- `arrivalTime` (string, required): Arrival time in HH:MM format (24-hour)
|
|
180
|
+
|
|
181
|
+
**Returns:** Promise<object> - Flight duration with detailed breakdown
|
|
182
|
+
|
|
183
|
+
**Example:**
|
|
184
|
+
\`\`\`javascript
|
|
185
|
+
const duration = await service.calculateFlightDuration(
|
|
186
|
+
'iata', 'LAX', '2026-02-15', '08:00',
|
|
187
|
+
'iata', 'JFK', '2026-02-15', '16:30'
|
|
188
|
+
);
|
|
189
|
+
console.log(duration.total_duration); // Total flight time
|
|
190
|
+
console.log(duration.duration_breakdown); // Hours, minutes breakdown
|
|
191
|
+
\`\`\`
|
|
210
192
|
|
|
211
193
|
---
|
|
212
194
|
|
|
@@ -214,235 +196,179 @@ Get cities with airports in a specific country.
|
|
|
214
196
|
|
|
215
197
|
### Search Airports by Country
|
|
216
198
|
|
|
217
|
-
|
|
199
|
+
\`\`\`javascript
|
|
218
200
|
const { SharpApiAirportsService } = require('@sharpapi/sharpapi-node-airports');
|
|
219
201
|
|
|
220
202
|
const service = new SharpApiAirportsService(process.env.SHARP_API_KEY);
|
|
221
203
|
|
|
222
|
-
async function
|
|
223
|
-
const
|
|
224
|
-
country: '
|
|
204
|
+
async function getUSAirports() {
|
|
205
|
+
const result = await service.getAirports({
|
|
206
|
+
country: 'US',
|
|
225
207
|
iata_assigned: true,
|
|
226
|
-
per_page:
|
|
208
|
+
per_page: 100
|
|
227
209
|
});
|
|
228
210
|
|
|
229
|
-
console.log(
|
|
211
|
+
console.log(\`Found \${result.meta.total} US airports with IATA codes\`);
|
|
230
212
|
|
|
231
|
-
|
|
232
|
-
console.log(
|
|
213
|
+
result.data.forEach(airport => {
|
|
214
|
+
console.log(\`\${airport.iata} - \${airport.name} (\${airport.city})\`);
|
|
233
215
|
});
|
|
234
216
|
}
|
|
235
217
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
### Flight Search Application
|
|
240
|
-
|
|
241
|
-
```javascript
|
|
242
|
-
const service = new SharpApiAirportsService(process.env.SHARP_API_KEY);
|
|
243
|
-
|
|
244
|
-
async function searchFlights(departure, arrival) {
|
|
245
|
-
// Get departure airport
|
|
246
|
-
const depAirport = await service.getAirportByIata(departure);
|
|
247
|
-
console.log(`Departure: ${depAirport.name}, ${depAirport.city}`);
|
|
248
|
-
|
|
249
|
-
// Get arrival airport
|
|
250
|
-
const arrAirport = await service.getAirportByIata(arrival);
|
|
251
|
-
console.log(`Arrival: ${arrAirport.name}, ${arrAirport.city}`);
|
|
252
|
-
|
|
253
|
-
// Calculate flight duration
|
|
254
|
-
const duration = await service.calculateFlightDuration(departure, arrival);
|
|
255
|
-
console.log(`Estimated Duration: ${duration.hours}h ${duration.minutes}m`);
|
|
256
|
-
console.log(`Distance: ${duration.distance} km`);
|
|
257
|
-
|
|
258
|
-
return {
|
|
259
|
-
from: depAirport,
|
|
260
|
-
to: arrAirport,
|
|
261
|
-
duration: duration
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
searchFlights('LHR', 'JFK').then(result => {
|
|
266
|
-
console.log('Flight Details:', result);
|
|
267
|
-
});
|
|
268
|
-
```
|
|
218
|
+
getUSAirports();
|
|
219
|
+
\`\`\`
|
|
269
220
|
|
|
270
|
-
###
|
|
221
|
+
### Get Specific Airport Details
|
|
271
222
|
|
|
272
|
-
|
|
223
|
+
\`\`\`javascript
|
|
273
224
|
const service = new SharpApiAirportsService(process.env.SHARP_API_KEY);
|
|
274
225
|
|
|
275
|
-
async function
|
|
276
|
-
|
|
277
|
-
const cities = await service.getCitiesByCountry(countryCode);
|
|
278
|
-
|
|
279
|
-
const destinations = await Promise.all(
|
|
280
|
-
cities.map(async (city) => {
|
|
281
|
-
const airports = await service.getAirports({
|
|
282
|
-
country: countryCode,
|
|
283
|
-
city: city,
|
|
284
|
-
iata_assigned: true,
|
|
285
|
-
per_page: 10
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
return {
|
|
289
|
-
city: city,
|
|
290
|
-
airports: airports.data.map(a => ({
|
|
291
|
-
code: a.iata,
|
|
292
|
-
name: a.name,
|
|
293
|
-
timezone: a.timezone
|
|
294
|
-
}))
|
|
295
|
-
};
|
|
296
|
-
})
|
|
297
|
-
);
|
|
226
|
+
async function getAirportDetails() {
|
|
227
|
+
const lax = await service.getAirportByIata('LAX');
|
|
298
228
|
|
|
299
|
-
|
|
229
|
+
console.log('Airport:', lax.name);
|
|
230
|
+
console.log('City:', lax.city);
|
|
231
|
+
console.log('Country:', lax.country);
|
|
232
|
+
console.log('Timezone:', lax.timezone);
|
|
233
|
+
console.log('Elevation:', lax.elevation, 'ft');
|
|
234
|
+
console.log('Coordinates:', lax.latitude, lax.longitude);
|
|
235
|
+
console.log('Codes: IATA:', lax.iata, 'ICAO:', lax.icao);
|
|
300
236
|
}
|
|
301
237
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
```
|
|
238
|
+
getAirportDetails();
|
|
239
|
+
\`\`\`
|
|
305
240
|
|
|
306
|
-
###
|
|
241
|
+
### Calculate Flight Duration
|
|
307
242
|
|
|
308
|
-
|
|
243
|
+
\`\`\`javascript
|
|
309
244
|
const service = new SharpApiAirportsService(process.env.SHARP_API_KEY);
|
|
310
245
|
|
|
311
|
-
async function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
console.log(` City: ${airport.city}, ${airport.country}`);
|
|
320
|
-
});
|
|
246
|
+
async function calculateFlight() {
|
|
247
|
+
// Flight from Los Angeles to New York
|
|
248
|
+
const duration = await service.calculateFlightDuration(
|
|
249
|
+
'iata', 'LAX',
|
|
250
|
+
'2026-02-15', '08:00',
|
|
251
|
+
'iata', 'JFK',
|
|
252
|
+
'2026-02-15', '16:30'
|
|
253
|
+
);
|
|
321
254
|
|
|
322
|
-
|
|
255
|
+
console.log('Flight Duration:', duration.human_readable);
|
|
256
|
+
console.log('Hours:', duration.duration_breakdown.hours);
|
|
257
|
+
console.log('Minutes:', duration.duration_breakdown.minutes);
|
|
258
|
+
console.log('Departure:', duration.departure_airport.name);
|
|
259
|
+
console.log('Arrival:', duration.arrival_airport.name);
|
|
323
260
|
}
|
|
324
261
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
```
|
|
262
|
+
calculateFlight();
|
|
263
|
+
\`\`\`
|
|
328
264
|
|
|
329
|
-
###
|
|
265
|
+
### Paginate Through Results
|
|
330
266
|
|
|
331
|
-
|
|
267
|
+
\`\`\`javascript
|
|
332
268
|
const service = new SharpApiAirportsService(process.env.SHARP_API_KEY);
|
|
333
269
|
|
|
334
|
-
async function
|
|
335
|
-
|
|
270
|
+
async function browseAirports() {
|
|
271
|
+
let currentPage = 1;
|
|
272
|
+
let hasMore = true;
|
|
336
273
|
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
// Find airports in each city
|
|
342
|
-
const fromAirports = await service.getAirports({
|
|
343
|
-
city: fromCity,
|
|
344
|
-
iata_assigned: true,
|
|
345
|
-
per_page: 1
|
|
274
|
+
while (hasMore && currentPage <= 5) {
|
|
275
|
+
const result = await service.getAirports({
|
|
276
|
+
per_page: 25,
|
|
277
|
+
page: currentPage
|
|
346
278
|
});
|
|
347
279
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
per_page: 1
|
|
280
|
+
console.log(\`Page \${currentPage}:\`);
|
|
281
|
+
result.data.forEach(airport => {
|
|
282
|
+
console.log(\` - \${airport.name}\`);
|
|
352
283
|
});
|
|
353
284
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
continue;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const fromAirport = fromAirports.data[0];
|
|
360
|
-
const toAirport = toAirports.data[0];
|
|
361
|
-
|
|
362
|
-
// Calculate duration
|
|
363
|
-
const duration = await service.calculateFlightDuration(
|
|
364
|
-
fromAirport.iata,
|
|
365
|
-
toAirport.iata
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
itinerary.push({
|
|
369
|
-
leg: i + 1,
|
|
370
|
-
from: {
|
|
371
|
-
city: fromCity,
|
|
372
|
-
airport: fromAirport.name,
|
|
373
|
-
code: fromAirport.iata
|
|
374
|
-
},
|
|
375
|
-
to: {
|
|
376
|
-
city: toCity,
|
|
377
|
-
airport: toAirport.name,
|
|
378
|
-
code: toAirport.iata
|
|
379
|
-
},
|
|
380
|
-
duration: duration
|
|
381
|
-
});
|
|
285
|
+
hasMore = result.links.next !== null;
|
|
286
|
+
currentPage++;
|
|
382
287
|
}
|
|
383
|
-
|
|
384
|
-
return itinerary;
|
|
385
288
|
}
|
|
386
289
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
console.log('Multi-City Itinerary:');
|
|
391
|
-
trip.forEach(leg => {
|
|
392
|
-
console.log(`\nLeg ${leg.leg}: ${leg.from.city} → ${leg.to.city}`);
|
|
393
|
-
console.log(` ${leg.from.code} to ${leg.to.code}`);
|
|
394
|
-
console.log(` Duration: ${leg.duration.hours}h ${leg.duration.minutes}m`);
|
|
395
|
-
});
|
|
396
|
-
```
|
|
290
|
+
browseAirports();
|
|
291
|
+
\`\`\`
|
|
397
292
|
|
|
398
293
|
---
|
|
399
294
|
|
|
400
295
|
## Use Cases
|
|
401
296
|
|
|
402
|
-
- **Travel Booking
|
|
403
|
-
- **Flight Search
|
|
404
|
-
- **
|
|
405
|
-
- **Mobile
|
|
406
|
-
- **
|
|
407
|
-
- **
|
|
408
|
-
- **Travel Comparison Sites**: Compare flight options
|
|
409
|
-
- **Tourism Applications**: Destination discovery
|
|
297
|
+
- **Travel Booking**: Display airport information in booking systems
|
|
298
|
+
- **Flight Search**: Enable airport code lookups and autocomplete
|
|
299
|
+
- **Trip Planning**: Calculate flight times for itinerary planning
|
|
300
|
+
- **Mobile Apps**: Integrate airport data into travel applications
|
|
301
|
+
- **Route Planning**: Determine travel times for multi-leg journeys
|
|
302
|
+
- **Logistics**: Calculate shipping times via air freight
|
|
410
303
|
|
|
411
304
|
---
|
|
412
305
|
|
|
413
|
-
##
|
|
414
|
-
|
|
415
|
-
- **Total Airports**: ~30,000 worldwide
|
|
416
|
-
- **Coverage**: All continents and major aviation hubs
|
|
417
|
-
- **Code Systems**: IATA, ICAO, and LID codes
|
|
418
|
-
- **Data Fields**: Name, city, country, timezone, elevation, coordinates
|
|
419
|
-
- **Updates**: Regular database maintenance
|
|
306
|
+
## API Endpoints
|
|
420
307
|
|
|
421
|
-
|
|
308
|
+
All endpoints are **synchronous** (return 200 OK immediately):
|
|
422
309
|
|
|
423
|
-
|
|
310
|
+
- **GET** `/airports` - List airports with filters
|
|
311
|
+
- **GET** `/airports/{uuid}` - Get airport by UUID
|
|
312
|
+
- **GET** `/airports/iata/{iata}` - Get airport by IATA code
|
|
313
|
+
- **GET** `/airports/icao/{icao}` - Get airport by ICAO code
|
|
314
|
+
- **GET** `/airports/lid/{lid}` - Get airport by LID code
|
|
315
|
+
- **GET** `/airports/flight_duration/{departureCodeType}/{departureCode}/{departureDate}/{departureTime}/{arrivalCodeType}/{arrivalCode}/{arrivalDate}/{arrivalTime}` - Calculate flight duration
|
|
424
316
|
|
|
425
|
-
|
|
426
|
-
-
|
|
427
|
-
-
|
|
428
|
-
- **Geographic Search**: Find airports by location
|
|
429
|
-
- **Duration Calculation**: Estimate flight times
|
|
430
|
-
- **Global Coverage**: Worldwide airport database
|
|
317
|
+
For detailed API specifications, refer to:
|
|
318
|
+
- [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsVj)
|
|
319
|
+
- [Product Page](https://sharpapi.com/en/catalog/utility/airports-database-flight-duration-calculator)
|
|
431
320
|
|
|
432
321
|
---
|
|
433
322
|
|
|
434
|
-
##
|
|
323
|
+
## Response Format
|
|
435
324
|
|
|
436
|
-
|
|
325
|
+
### Airport Object
|
|
437
326
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
327
|
+
\`\`\`json
|
|
328
|
+
{
|
|
329
|
+
"id": "1ef266de-5a6c-67d6-86a1-06bb2780ed98",
|
|
330
|
+
"icao": "00AA",
|
|
331
|
+
"iata": "",
|
|
332
|
+
"lid": "00AA",
|
|
333
|
+
"name": "Aero B Ranch Airport",
|
|
334
|
+
"city": "Leoti",
|
|
335
|
+
"subdivision": "Kansas",
|
|
336
|
+
"country": "US",
|
|
337
|
+
"timezone": "America/Chicago",
|
|
338
|
+
"elevation": 3435,
|
|
339
|
+
"latitude": 38.7,
|
|
340
|
+
"longitude": -101.47
|
|
341
|
+
}
|
|
342
|
+
\`\`\`
|
|
343
|
+
|
|
344
|
+
### Paginated Response
|
|
345
|
+
|
|
346
|
+
\`\`\`json
|
|
347
|
+
{
|
|
348
|
+
"data": [ /* array of airport objects */ ],
|
|
349
|
+
"links": {
|
|
350
|
+
"first": "https://sharpapi.com/api/v1/airports?page=1",
|
|
351
|
+
"last": "https://sharpapi.com/api/v1/airports?page=1128",
|
|
352
|
+
"prev": null,
|
|
353
|
+
"next": "https://sharpapi.com/api/v1/airports?page=2"
|
|
354
|
+
},
|
|
355
|
+
"meta": {
|
|
356
|
+
"current_page": 1,
|
|
357
|
+
"from": 1,
|
|
358
|
+
"last_page": 1128,
|
|
359
|
+
"per_page": 25,
|
|
360
|
+
"to": 25,
|
|
361
|
+
"total": 28186
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
\`\`\`
|
|
441
365
|
|
|
442
366
|
---
|
|
443
367
|
|
|
444
368
|
## Related Packages
|
|
445
369
|
|
|
370
|
+
- [@sharpapi/sharpapi-node-travel-review-sentiment](https://www.npmjs.com/package/@sharpapi/sharpapi-node-travel-review-sentiment)
|
|
371
|
+
- [@sharpapi/sharpapi-node-web-scraping](https://www.npmjs.com/package/@sharpapi/sharpapi-node-web-scraping)
|
|
446
372
|
- [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
|
|
447
373
|
|
|
448
374
|
---
|
package/package.json
CHANGED
package/src/CLAUDE.md
ADDED
|
@@ -2,6 +2,9 @@ const { SharpApiCoreService } = require('@sharpapi/sharpapi-node-core');
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Service for accessing Airports Database & Flight Duration Calculator API using SharpAPI.com
|
|
5
|
+
*
|
|
6
|
+
* Provides access to nearly 30,000 airports worldwide with detailed information including
|
|
7
|
+
* ICAO, IATA, LID codes, geographical data, and flight duration calculations.
|
|
5
8
|
*/
|
|
6
9
|
class SharpApiAirportsService extends SharpApiCoreService {
|
|
7
10
|
/**
|
|
@@ -10,106 +13,106 @@ class SharpApiAirportsService extends SharpApiCoreService {
|
|
|
10
13
|
* @param {string} [apiBaseUrl='https://sharpapi.com/api/v1'] - API base URL
|
|
11
14
|
*/
|
|
12
15
|
constructor(apiKey, apiBaseUrl = 'https://sharpapi.com/api/v1') {
|
|
13
|
-
super(apiKey, apiBaseUrl, '@sharpapi/sharpapi-node-airports/1.0.
|
|
16
|
+
super(apiKey, apiBaseUrl, '@sharpapi/sharpapi-node-airports/1.0.2');
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
|
-
* Get list of airports with optional filters
|
|
20
|
+
* Get list of airports with optional filters (synchronous endpoint)
|
|
18
21
|
*
|
|
19
22
|
* @param {object} [filters={}] - Filter options
|
|
20
23
|
* @param {number} [filters.per_page=25] - Results per page (max 100)
|
|
21
24
|
* @param {boolean} [filters.iata_assigned] - Filter by IATA code assignment
|
|
22
25
|
* @param {boolean} [filters.icao_assigned] - Filter by ICAO code assignment
|
|
23
|
-
* @param {
|
|
24
|
-
* @param {string} [filters.
|
|
25
|
-
* @param {string} [filters.
|
|
26
|
-
* @
|
|
26
|
+
* @param {boolean} [filters.lid_assigned] - Filter by LID code assignment
|
|
27
|
+
* @param {string} [filters.country] - Filter by 2-letter country code
|
|
28
|
+
* @param {string} [filters.timezone] - Filter by full timezone name
|
|
29
|
+
* @param {string} [filters.name] - Filter by airport name (partial match allowed)
|
|
30
|
+
* @param {string} [filters.city] - Filter by city name (partial match allowed)
|
|
31
|
+
* @returns {Promise<object>} - Paginated list of airports with metadata
|
|
27
32
|
*/
|
|
28
33
|
async getAirports(filters = {}) {
|
|
29
34
|
const response = await this.makeRequest('GET', '/airports', filters);
|
|
30
|
-
return response
|
|
35
|
+
return response;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
/**
|
|
34
|
-
* Get airport information by
|
|
35
|
-
*
|
|
36
|
-
* @param {string} iataCode - The IATA code of the airport
|
|
37
|
-
* @returns {Promise<object>} - Airport information
|
|
38
|
-
*/
|
|
39
|
-
async getAirportByIata(iataCode) {
|
|
40
|
-
const response = await this.makeRequest('GET', `/airports/iata/${iataCode}`);
|
|
41
|
-
return response.data;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Get airport information by ICAO code
|
|
46
|
-
*
|
|
47
|
-
* @param {string} icaoCode - The ICAO code of the airport
|
|
48
|
-
* @returns {Promise<object>} - Airport information
|
|
49
|
-
*/
|
|
50
|
-
async getAirportByIcao(icaoCode) {
|
|
51
|
-
const response = await this.makeRequest('GET', `/airports/icao/${icaoCode}`);
|
|
52
|
-
return response.data;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Get airport information by UUID
|
|
39
|
+
* Get airport information by UUID (synchronous endpoint)
|
|
57
40
|
*
|
|
58
41
|
* @param {string} uuid - The UUID of the airport
|
|
59
42
|
* @returns {Promise<object>} - Airport information
|
|
60
43
|
*/
|
|
61
44
|
async getAirportByUuid(uuid) {
|
|
62
45
|
const response = await this.makeRequest('GET', `/airports/${uuid}`);
|
|
63
|
-
return response
|
|
46
|
+
return response;
|
|
64
47
|
}
|
|
65
48
|
|
|
66
49
|
/**
|
|
67
|
-
* Get
|
|
50
|
+
* Get airport information by IATA code (synchronous endpoint)
|
|
68
51
|
*
|
|
69
|
-
* @param {
|
|
70
|
-
* @
|
|
71
|
-
* @param {number} [radius=100] - Radius in kilometers
|
|
72
|
-
* @param {number} [limit=10] - Maximum number of results to return
|
|
73
|
-
* @returns {Promise<object>} - Nearby airports
|
|
52
|
+
* @param {string} iataCode - The IATA code of the airport (e.g., 'LAX', 'JFK')
|
|
53
|
+
* @returns {Promise<object>} - Airport information
|
|
74
54
|
*/
|
|
75
|
-
async
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
return response.data;
|
|
55
|
+
async getAirportByIata(iataCode) {
|
|
56
|
+
const response = await this.makeRequest('GET', `/airports/iata/${iataCode}`);
|
|
57
|
+
return response;
|
|
79
58
|
}
|
|
80
59
|
|
|
81
60
|
/**
|
|
82
|
-
*
|
|
61
|
+
* Get airport information by ICAO code (synchronous endpoint)
|
|
83
62
|
*
|
|
84
|
-
* @param {string}
|
|
85
|
-
* @
|
|
86
|
-
* @returns {Promise<object>} - Flight duration information
|
|
63
|
+
* @param {string} icaoCode - The ICAO code of the airport (e.g., 'KLAX', 'KJFK')
|
|
64
|
+
* @returns {Promise<object>} - Airport information
|
|
87
65
|
*/
|
|
88
|
-
async
|
|
89
|
-
const response = await this.makeRequest('GET', `/
|
|
90
|
-
return response
|
|
66
|
+
async getAirportByIcao(icaoCode) {
|
|
67
|
+
const response = await this.makeRequest('GET', `/airports/icao/${icaoCode}`);
|
|
68
|
+
return response;
|
|
91
69
|
}
|
|
92
70
|
|
|
93
71
|
/**
|
|
94
|
-
* Get
|
|
72
|
+
* Get airport information by LID code (synchronous endpoint)
|
|
95
73
|
*
|
|
96
|
-
* @
|
|
74
|
+
* @param {string} lidCode - The LID code of the airport
|
|
75
|
+
* @returns {Promise<object>} - Airport information
|
|
97
76
|
*/
|
|
98
|
-
async
|
|
99
|
-
const response = await this.makeRequest('GET',
|
|
100
|
-
return response
|
|
77
|
+
async getAirportByLid(lidCode) {
|
|
78
|
+
const response = await this.makeRequest('GET', `/airports/lid/${lidCode}`);
|
|
79
|
+
return response;
|
|
101
80
|
}
|
|
102
81
|
|
|
103
82
|
/**
|
|
104
|
-
*
|
|
83
|
+
* Calculate flight duration between two airports (synchronous endpoint)
|
|
84
|
+
*
|
|
85
|
+
* @param {string} departureCodeType - Type of departure code: 'iata', 'icao', or 'lid'
|
|
86
|
+
* @param {string} departureCode - Departure airport code
|
|
87
|
+
* @param {string} departureDate - Departure date in YYYY-MM-DD format
|
|
88
|
+
* @param {string} departureTime - Departure time in HH:MM format
|
|
89
|
+
* @param {string} arrivalCodeType - Type of arrival code: 'iata', 'icao', or 'lid'
|
|
90
|
+
* @param {string} arrivalCode - Arrival airport code
|
|
91
|
+
* @param {string} arrivalDate - Arrival date in YYYY-MM-DD format
|
|
92
|
+
* @param {string} arrivalTime - Arrival time in HH:MM format
|
|
93
|
+
* @returns {Promise<object>} - Flight duration information with detailed breakdown
|
|
105
94
|
*
|
|
106
|
-
* @
|
|
107
|
-
*
|
|
95
|
+
* @example
|
|
96
|
+
* // Calculate flight from LAX to JFK
|
|
97
|
+
* const duration = await service.calculateFlightDuration(
|
|
98
|
+
* 'iata', 'LAX', '2026-02-15', '08:00',
|
|
99
|
+
* 'iata', 'JFK', '2026-02-15', '16:30'
|
|
100
|
+
* );
|
|
108
101
|
*/
|
|
109
|
-
async
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
async calculateFlightDuration(
|
|
103
|
+
departureCodeType,
|
|
104
|
+
departureCode,
|
|
105
|
+
departureDate,
|
|
106
|
+
departureTime,
|
|
107
|
+
arrivalCodeType,
|
|
108
|
+
arrivalCode,
|
|
109
|
+
arrivalDate,
|
|
110
|
+
arrivalTime
|
|
111
|
+
) {
|
|
112
|
+
const endpoint = `/airports/flight_duration/${departureCodeType}/${departureCode}/${departureDate}/${departureTime}/${arrivalCodeType}/${arrivalCode}/${arrivalDate}/${arrivalTime}`;
|
|
113
|
+
const response = await this.makeRequest('GET', endpoint);
|
|
114
|
+
return response;
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
|
|
115
|
-
module.exports = { SharpApiAirportsService };
|
|
118
|
+
module.exports = { SharpApiAirportsService };
|