Git Product home page Git Product logo

ravishn / openflightsapi-springboot-aop-security-swagger Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 48.01 MB

SpringBoot application using OpenFlights data exposing REST API endpoints, Aspect Oriented Programming using Spring AOP, Authorisation using Spring Security, Metrics using Spring Actuator and Swagger API documentation using Springfox

Dockerfile 0.87% Java 44.32% HTML 43.31% CSS 4.82% JavaScript 6.69%
java-8 spring spring-boot springboot-application spring-security spring-data-jpa hibernate-jpa swagger2 aspect-oriented-programming aop-aspectj

openflightsapi-springboot-aop-security-swagger's Introduction

OpenFlightsAPI

SpringBoot application integrated with OpenFlights data, secured by Spring Security and expose endpoints that provide Flights data based on airports.

OpenFlights API Specification

https://openflights.org/data.html

Requirement

  1. Use the Airline, Airport and Routes data from OpenFlights spec
  2. Download and read the .dat files
  3. Define a schema and store the data into an in-memory database
  4. Provide API' for
    1. Flights flying into a specified airport
    2. Flights flyout out of a specified airport
    3. Flights between 2 specified airports
  5. Authenticate and authorise endpoints using Basic Authorisation(username/password)
  6. Document API using Swagger

OpenFlightsAPI-SpringBoot

SpringBoot application integrated with OpenFlights data to get flights information from airports, airlines and routes

Steps to run the API

Clone the OpenFlightsAPI-SpringBoot and open the project "com.foxtel.spring.demo"

  1. Run Application.java - main Spring boot application
  2. 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
  3. Once the application is running, make a note of the port(should be 8080 by default)
  4. 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
    },
    ...
]
  1. 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
    },
    ...
]
  1. 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"
    },
    ...
]

Steps to read Swagger API documentation

  1. 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.
  2. Copy the JSON response and paste it on Swagger Editor webpage https://editor.swagger.io/

-OR-

  1. 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
  2. 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#/

API hosting

  • 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

openflightsapi-springboot-aop-security-swagger's People

Contributors

ravishn avatar ravishnagaraj avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.