Simple REST API that returns information about airports.
This REST API is a part of Flight Search Engine project.
I've created this project to get information about distance between two airports, I'm using it in
random-flight-generator project. However, this API will also
show information about country or city of airport. It uses mongoDB database to store data.
- Spring
- Java 17
- MongoDB
git clone https://github.com/bladeours/airport-api.git
docker-compose -d
App runs on 8081 port, but you can change it in .env
file. I needed to use fvilers/mongo-seed
image because
it's the best way to import data to mongoDB in container. mongo
container
starts, then mongo-seed
import data to mongo
and shutdowns.
- check official mongoDB documentation
- create database with name
airport
- on Windows download Database Tools
- on linux install
mongo-tools
- import json file
mongoimport --uri mongodb+srv://<USERNAME>:<PASSWORD>@<CLUSTER_NAME>/airport --collection airport --type json --file airport.json --jsonArray
this app requires Java 17
java -jar airportApi.jar
GET: /airport/{code}
Return:
- code
- city
- country
- longitude
- latitude
Here is sample output:
curl localhost:8081/airport/WAW
{
"code": "WAW",
"city": "Warsaw",
"country": "Poland",
"longitude": "20.96710014",
"latitude": "52.16569901"
}
GET: /airports
return all airports
GET: /distance/{departure}/{arrival}
return distance between two airports in km
localhost:8081/distance/waw/aby
{
"departure": {
"code": "WAW",
"city": "Warsaw",
"country": "Poland",
"longitude": "20.96710014",
"latitude": "52.16569901"
},
"arrival": {
"code": "ABY",
"city": "Albany, GA",
"country": "USA",
"longitude": "-84.19450378",
"latitude": "31.53549957"
},
"distance_km": 8223
}
// TODO