A RESTful API built using Spring Boot to search for available flights between given origins and destinations. It supports pagination and sorting by various parameters.
- Find list of flights from Origin to Destination.
- Sort results based on multiple fields (e.g., price, departure time).
- Paginate results.
- Java 11 or later
- Maven
- Clone the repository:
git clone https://github.com/your-repo/flight-search-api.git
- Navigate to the project directory:
cd flight-search-api
- Edit the application.properties for MySQL DB connection.
- Build the project:
mvn clean install
- Run the application:
mvn spring-boot:run
Swagger UI : http://localhost:8080/swagger-ui/index.html
GET /flights?origin=AMS&destination=DEL
GET /flights?origin=AMS&destination=DEL&page=1&size=10
GET /flights?origin=AMS&destination=DEL&sortFields=price,departureTime&sortDirections=asc,desc&page=1&size=10
origin
(required): The origin airport code.destination
(required): The destination airport code.sortFields
(optional): The fields by which to sort the results. Comma-separated.sortDirections
(optional): The direction ('asc' or 'desc') for each sort field. Comma-separated.page
(optional): The page number for pagination. Default is 0.size
(optional): The number of records per page. Default is 10.
Returns a JSON object containing the flight data and pagination information.
- Spring Web
- Spring Data JPA
- H2 Database / MySQL
Add the following to your pom.xml
:
<dependencies>
<!-- Spring Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- H2 Database -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
- Yarish Kumar J.
- [email protected] / 9980044534 / https://www.linkedin.com/in/yarish-kumar-j/