bladeours / airport-api

api to get airport codes and distance between them

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Airports REST API

Simple REST API that returns information about airports.

Table of Contents

General Info

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.

Technologies Used

  • Spring
  • Java 17
  • MongoDB

Setup

Run with Docker

Docker-compose

  • 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.

Install on local machine

Install mongoDB

Import collection

  • 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

Run API

this app requires Java 17

  • java -jar airportApi.jar

Endpoints

Airport

Airport by code

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"
}

All airports

GET: /airports
return all airports

Distance

Distance between 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
}

Authorization

// TODO

About

api to get airport codes and distance between them


Languages

Language:Java 98.0%Language:Dockerfile 1.9%Language:Shell 0.1%