-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
545 lines (487 loc) · 12.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
const express = require('express');
const app = express();
const port = 3000;
const airlinedata = require('./airlinedata.json');
const airportdata = require('./airportdata.json');
const cors = require('cors');
app.use(cors());
app.get('/', (req, res) => {
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Airport API Documentation</title>
<style>
body {
font-family: 'DM Sans', sans-serif;
margin: 20px;
background-color: #121212;
color: #E0E0E0;
line-height: 1.6;
}
h1, h2 {
color: #03DAC6;
}
a {
color: #BB86FC;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.container {
max-width: 800px;
margin: 0 auto;
}
pre {
background-color: #1F1B24;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
color: #E0E0E0;
font-size: 14px;
}
.endpoint {
background-color: #1E1E1E;
padding: 15px;
border: 1px solid #2C2C2C;
border-radius: 8px;
margin-bottom: 20px;
}
.title {
font-size: 1.2em;
font-weight: 700;
margin-bottom: 10px;
color: #03DAC6;
}
footer {
margin-top: 40px;
text-align: center;
font-size: 0.9em;
color: #757575;
}
.error {
color: #CF6679;
}
.success {
color: #03DAC6;
}
.section-header {
border-left: 4px solid #03DAC6;
padding-left: 10px;
margin-bottom: 20px;
font-size: 1.5em;
font-weight: 700;
}
</style>
</head>
<body>
<h1>Airport API Documentation</h1>
<p>Welcome to the official documentation for the Airport API! This API provides detailed information on airports and airlines in India, such as airport codes, locations, types, and airlines operating in India.</p>
<p>Base URL: <a href="https://aerokey-api.vercel.app" target="_blank">https://aerokey-api.vercel.app</a></p>
<p>Author: <a href="https://abhishekjainn.vercel.app" target="_blank">Abhishek Jain</a></p>
<h2>API Endpoints</h2>
<div class="endpoint">
<div class="title">1. Get all Airports</div>
<p>Request:</p>
<pre>GET /v1/airports</pre>
<p>Response:</p>
<pre>
{
"total": 1000,
"airports": [...],
"message": "Success",
"status": 200
}
</pre>
<p>This endpoint retrieves a list of all airports.</p>
</div>
<div class="endpoint">
<div class="title">2. Get Airport by Code</div>
<p>Request:</p>
<pre>GET /v1/airports/code/:code</pre>
<p>Response:</p>
<pre>
{
"airport_code": "DEL",
"airport_name": "Indira Gandhi International Airport",
"city_name": "New Delhi",
"state_name": "Delhi",
"airport_type": "International",
"pincode": "110037",
"state_code": "DL",
"message": "Success",
"status": 200
}
</pre>
<p>Error Message (if not found):</p>
<pre>
{
"message": "Airport not found",
"status": 404
}
</pre>
<p>This endpoint allows you to retrieve information for a specific airport by its airport code.</p>
</div>
<div class="endpoint">
<div class="title">3. Get Airport by Name</div>
<p>Request:</p>
<pre>GET /v1/airports/name/:name</pre>
<p>Response:</p>
<pre>
{
"airport_code": "DEL",
"airport_name": "Indira Gandhi International Airport",
"city_name": "New Delhi",
"state_name": "Delhi",
"airport_type": "International",
"pincode": "110037",
"state_code": "DL",
"message": "Success",
"status": 200
}
</pre>
<p>Error Message (if not found):</p>
<pre>
{
"message": "Airport not found",
"status": 404
}
</pre>
<p>This endpoint allows you to retrieve information for a specific airport by its name.</p>
</div>
<div class="endpoint">
<div class="title">4. Get Airport by City</div>
<p>Request:</p>
<pre>GET /v1/airports/city/:city</pre>
<p>Response:</p>
<pre>
{
"airport_code": "DEL",
"airport_name": "Indira Gandhi International Airport",
"city_name": "New Delhi",
"state_name": "Delhi",
"airport_type": "International",
"pincode": "110037",
"state_code": "DL",
"message": "Success",
"status": 200
}
</pre>
<p>Error Message (if not found):</p>
<pre>
{
"message": "Airport not found",
"status": 404
}
</pre>
<p>This endpoint allows you to retrieve information for a specific airport by its city.</p>
</div>
<div class="endpoint">
<div class="title">5. Get Airports by State</div>
<p>Request:</p>
<pre>GET /v1/airports/state/:state</pre>
<p>Response:</p>
<pre>
[
{
"airport_code": "BOM",
"airport_name": "Chhatrapati Shivaji Maharaj International Airport",
"city_name": "Mumbai",
"state_name": "Maharashtra",
"airport_type": "International",
"pincode": "400099",
"state_code": "MH",
"message": "Success",
"status": 200
},
...
]
</pre>
<p>Error Message (if no airports found):</p>
<pre>
{
"message": "No airports found in this state",
"status": 404
}
</pre>
<p>This endpoint allows you to retrieve airports in a specific state.</p>
</div>
<div class="endpoint">
<div class="title">6. Get Airport by Pincode</div>
<p>Request:</p>
<pre>GET /v1/airports/pincode/:pincode</pre>
<p>Response:</p>
<pre>
{
"airport_code": "BLR",
"airport_name": "Kempegowda International Airport",
"city_name": "Bengaluru",
"state_name": "Karnataka",
"airport_type": "International",
"pincode": "560300",
"state_code": "KA",
"message": "Success",
"status": 200
}
</pre>
<p>Error Message (if not found):</p>
<pre>
{
"message": "Airport not found",
"status": 404
}
</pre>
<p>This endpoint allows you to retrieve information for a specific airport by its pincode.</p>
</div>
<div class="endpoint">
<div class="title">7. Get Airports by State Code</div>
<p>Request:</p>
<pre>GET /v1/airports/statecode/:statecode</pre>
<p>Response:</p>
<pre>
[
{
"airport_code": "DEL",
"airport_name": "Indira Gandhi International Airport",
"city_name": "New Delhi",
"state_name": "Delhi",
"airport_type": "International",
"pincode": "110037",
"state_code": "DL",
"message": "Success",
"status": 200
},
...
]
</pre>
<p>Error Message (if no airports found):</p>
<pre>
{
"message": "No airports found for this state code",
"status": 404
}
</pre>
<p>This endpoint allows you to retrieve airports in a specific state code.</p>
</div>
<div class="endpoint">
<div class="title">8. Get Airports by Type</div>
<p>Request:</p>
<pre>GET /v1/airports/airporttype/:airporttype</pre>
<p>Response:</p>
<pre>
[
{
"airport_code": "DEL",
"airport_name": "Indira Gandhi International Airport",
"city_name": "New Delhi",
"state_name": "Delhi",
"airport_type": "International",
"pincode": "110037",
"state_code": "DL",
"message": "Success",
"status": 200
},
...
]
</pre>
<p>Error Message (if no airports found):</p>
<pre>
{
"message": "No airports found",
"status": 404
}
</pre>
<p>This endpoint allows you to retrieve airports based on their type (e.g., International, Domestic).</p>
</div>
<h2>Airline Endpoints</h2>
<div class="endpoint">
<div class="title">1. Get all Airlines</div>
<p>Request:</p>
<pre>GET /v1/airlines</pre>
<p>Response:</p>
<pre>
{
"airlines": [...]
}
</pre>
<p>This endpoint retrieves a list of all airlines.</p>
</div>
<div class="endpoint">
<div class="title">2. Get Airline by IATA Code</div>
<p>Request:</p>
<pre>GET /v1/airlines/code/:iata</pre>
<p>Response:</p>
<pre>
{
"iata_code": "AI",
"airline_name": "Air India",
"message": "Success",
"status": 200
}
</pre>
<p>Error Message (if not found):</p>
<pre>
{
"message": "Airline not found",
"status": 404
}
</pre>
<p>This endpoint allows you to retrieve an airline's information by its IATA code.</p>
</div>
<div class="endpoint">
<div class="title">3. Get Airline by Name</div>
<p>Request:</p>
<pre>GET /v1/airlines/name/:name</pre>
<p>Response:</p>
<pre>
{
"iata_code": "AI",
"airline_name": "Air India",
"message": "Success",
"status": 200
}
</pre>
<p>Error Message (if not found):</p>
<pre>
{
"message": "Airline not found",
"status": 404
}
</pre>
<p>This endpoint allows you to retrieve an airline's information by its name.</p>
</div>
<footer>
<p>For more information or questions, contact <a href="https://abhishekjainn.vercel.app" target="_blank">Abhishek Jain</a>.</p>
</footer>
</body>
</html>
`);
});
app.get('/v1/airports', (req, res) => {
res.json({
total: airportdata.length,
airports: airportdata,
message: 'Success',
status: 200,
});
});
app.get('/v1/airports/code/:code', (req, res) => {
const airport = airportdata.find(
(airport) =>
airport.airport_code.toLowerCase() === req.params.code.toLowerCase()
);
if (!airport) {
return res.status(404).json({ message: 'Airport not found', status: 404 });
}
res.json(airport);
});
app.get('/v1/airports/name/:name', (req, res) => {
const airport = airportdata.find(
(airport) =>
airport.airport_name.toLowerCase() === req.params.name.toLowerCase()
);
if (!airport) {
return res.status(404).json({ message: 'Airport not found' });
}
res.json(airport);
});
app.get('/v1/airports/city/:city', (req, res) => {
const airport = airportdata.find(
(airport) =>
airport.city_name.toLowerCase() === req.params.city.toLowerCase()
);
if (!airport) {
return res.status(404).json({ message: 'Airport not found' });
}
res.json(airport);
});
app.get('/v1/airports/state/:state', (req, res) => {
// Filter all airports in the specified state
const airports = airportdata.filter(
(airport) =>
airport.state_name.toLowerCase() === req.params.state.toLowerCase()
);
// If no airports are found, return a 404 error
if (airports.length === 0) {
return res.status(404).json({ message: 'No airports found in this state' });
}
// Return the list of airports
res.json(airports);
});
app.get('/v1/airports/pincode/:pincode', (req, res) => {
const airport = airportdata.find(
(airport) => airport.pincode === req.params.pincode
);
if (!airport) {
return res.status(404).json({ message: 'Airport not found' });
}
res.json(airport);
});
app.get('/v1/airports/statecode/:statecode', (req, res) => {
// Filter all airports with the specified state code
const airports = airportdata.filter(
(airport) =>
airport.state_code.toLowerCase() === req.params.statecode.toLowerCase()
);
// If no airports are found, return a 404 error
if (airports.length === 0) {
return res
.status(404)
.json({ message: 'No airports found for this state code' });
}
// Return the list of airports
res.json(airports);
});
app.get('/v1/airports/airporttype/:airporttype', (req, res) => {
const airports = airportdata.filter(
(airport) =>
airport.airport_type.toLowerCase() ===
req.params.airporttype.toLowerCase()
);
if (!airports.length) {
return res.status(404).json({ message: 'No airports found' });
}
res.json(airports);
});
//airline Routes
app.get('/v1/airlines', (req, res) => {
res.json({
airlines: airlinedata,
});
});
app.get('/v1/airlines/code/:iata', (req, res) => {
const airline = airlinedata.find(
(airline) =>
airline.iata_code.toLowerCase() === req.params.iata.toLowerCase()
);
if (!airline) {
return res.status(404).json({ message: 'Airline not found' });
}
res.json(airline);
});
app.get('/v1/airlines/name/:name', (req, res) => {
const airline = airlinedata.find(
(airline) =>
airline.airline_name.toLowerCase() === req.params.name.toLowerCase()
);
if (!airline) {
return res.status(404).json({ message: 'Airline not found' });
}
res.json(airline);
});
app.get('/v1/airlines/name/:name', (req, res) => {
const airline = airlinedata.find(
(airline) =>
airline.airline_name.toLowerCase() === req.params.name.toLowerCase()
);
if (!airline) {
return res.status(404).json({ message: 'Airline not found' });
}
res.json(airline);
});
app.listen(port, () => {
console.log(`Aerokey running live at http://localhost:${port}`);
});