Spring Boot REST API for managing railway tickets with in-memory storage, CRUD operations, and pantry-service integration through RestTemplate GET, POST, PUT, and DELETE calls.
This project demonstrates a compact Spring Boot API for railway ticket management with a simple inter-service communication pattern. It builds on the earlier railway workflow by fetching meal details from a pantry service, creating default meal records during ticket creation, synchronizing meal updates and deletes, and exposing a dedicated endpoint for premium-meal updates.
- Spring Boot REST API setup
POSTendpoint for saving ticket dataGETendpoint for listing all saved ticketsGETendpoint for retrieving a ticket by PNRPUTendpoint for updating an existing ticketDELETEendpoint for deleting a ticket by PNR- Dedicated
PUTendpoint for updating meal premium status - In-memory storage using
ListandMap - Custom exception handling for invalid or missing tickets
- Service-to-service communication with
RestTemplate getForObject()usage for external readspostForEntity()usage for external createsexchange()usage for external updates and deletes
- Java 17
- Spring Boot 3
- Spring Web
- Maven
- JUnit 5
railway-ticket-api/
├── CHANGELOG.md
├── README.md
├── pom.xml
├── mvnw
├── mvnw.cmd
└── src/
└── main/
├── java/railway/com/example/RailwayAndMeal/
│ ├── communicator/
│ ├── controller/
│ ├── customException/
│ ├── Entity/
│ ├── service/
│ └── RailwayAndMealApplication.java
└── resources/
└── application.properties
- Open a terminal in the project root.
- Run
mvn test. - Run
mvn spring-boot:run. - Ensure the pantry or meal service is available on
http://localhost:8081. - Use the API under
http://localhost:8080/railway.
Useful endpoints:
POST /railway/ticketGET /railway/ticketsGET /railway/ticket/{pnr}PUT /railway/ticketPUT /railway/ticket/{pnr}/premium/{isPremium}DELETE /railway/ticket/{pnr}
Example request body:
{
"pnr": 1234567890,
"name": "Aarav",
"age": 28,
"birth": "LOWER"
}- Shows how a basic railway ticket API can coordinate full CRUD synchronization with another service
- Demonstrates
RestTemplatepatterns for read, create, update, and delete operations - Adds a focused premium-update endpoint to illustrate targeted cross-service updates
- Keeps persistence intentionally simple so the service integration flow stays easy to follow
- Suggested repository description:
Java 17 Spring Boot REST API for railway ticket management with CRUD operations and pantry-service synchronization using RestTemplate. - Suggested topics:
java,java-17,spring-boot,rest-api,resttemplate,microservices,railway-ticket,service-integration,maven,learning-project,portfolio-project