SpringBoot application integrated with OpenFlights data, secured by Spring Security and expose endpoints that provide Flights data based on airports.
https://openflights.org/data.html
- Use the Airline, Airport and Routes data from OpenFlights spec
- Download and read the .dat files
- Define a schema and store the data into an in-memory database
- Provide API' for
- Flights flying into a specified airport
- Flights flyout out of a specified airport
- Flights between 2 specified airports
- Authenticate and authorise endpoints using Basic Authorisation(username/password)
- Document API using Swagger
SpringBoot application integrated with OpenFlights data to get flights information from airports, airlines and routes
Clone the OpenFlightsAPI-SpringBoot and open the project "com.foxtel.spring.demo"
- Run Application.java - main Spring boot application
- data.sql should accept relative path of the .dat files, if the application fails to launch, try providing the absolute path of the .dat files. Some versions of H2 database have this bug
- Once the application is running, make a note of the port(should be 8080 by default)
- Run the endpoint /flights/in/{airportId} with username and password in the AUTH headers if using Postman, enter credentials in the popup if using browser for flights flying in to the airport Ex. http://localhost:8080/flights/in/2290 should return the JSON response
[
{
"airportName": "Memanbetsu Airport",
"airlineId": "1",
"airlineName": "Private flight",
"destinataionAirportId": "2290",
"sourceAirportId": null,
"active": null,
"stops": null
},
{
"airportName": "Memanbetsu Airport",
"airlineId": "3",
"airlineName": "1Time Airline",
"destinataionAirportId": "2290",
"sourceAirportId": null,
"active": null,
"stops": null
},
{
"airportName": "Memanbetsu Airport",
"airlineId": "10",
"airlineName": "40-Mile Air",
"destinataionAirportId": "2290",
"sourceAirportId": null,
"active": null,
"stops": null
},
...
]
- Run the endpoint /flights/out/{airportId} with username and password in the AUTH headers if using Postman, enter credentials in the popup if using browser for flights flying out from the airport Ex. http://localhost:8080/flights/out/2290 should return the JSON response
[
{
"airportName": "Memanbetsu Airport",
"airlineId": "1",
"airlineName": "Private flight",
"destinataionAirportId": null,
"sourceAirportId": "2290",
"active": null,
"stops": null
},
{
"airportName": "Memanbetsu Airport",
"airlineId": "3",
"airlineName": "1Time Airline",
"destinataionAirportId": null,
"sourceAirportId": "2290",
"active": null,
"stops": null
},
{
"airportName": "Memanbetsu Airport",
"airlineId": "10",
"airlineName": "40-Mile Air",
"destinataionAirportId": null,
"sourceAirportId": "2290",
"active": null,
"stops": null
},
...
]
- Run the endpoint /flights/route/{sourceAirportId}/{destinationAirportId} with username and password in the AUTH headers if using Postman, enter credentials in the popup if using browser for flights flying between two airports Ex. http://localhost:8080/flights/route/3393/3361 should return the JSON response
[
{
"airportName": null,
"airlineId": null,
"airlineName": "Private flight",
"destinataionAirportId": "3361",
"sourceAirportId": "3393",
"active": "Y",
"stops": "0"
},
{
"airportName": null,
"airlineId": null,
"airlineName": "1Time Airline",
"destinataionAirportId": "3361",
"sourceAirportId": "3393",
"active": "Y",
"stops": "0"
},
{
"airportName": null,
"airlineId": null,
"airlineName": "40-Mile Air",
"destinataionAirportId": "3361",
"sourceAirportId": "3393",
"active": "Y",
"stops": "0"
},
...
]
- Run the endpoint http://localhost:8080/flights/api/docs. This will redirect to default Swagger documentation API http://localhost:8080/v2/api-docs which returns a JSON response.
- Copy the JSON response and paste it on Swagger Editor webpage https://editor.swagger.io/
-OR-
- Enable Swagger UI in the build.gradle - compile 'io.springfox:springfox-swagger-ui:2.9.2' This exposes the Swagger API documentation on to the Swagger UI endpoint
- Run the endpoint on the browser. This returns a HTML page where you can run the API's and test them out. http://localhost:8080/flights/api/docs/ui. This will redirect to default Swagger documentation UI page http://localhost:8080/swagger-ui.html#/
- This application has been hosted on Heroku and can be acccessed via this link - https://openfligthsapi.herokuapp.com/swagger-ui.html
- API is authorised by username and password mentioned in the application.properties using Spring Security
- Every merge from a PR triggers the deployment pipeline and hosts the new version of this API on Heroku