This is a Spring Boot REST API that simulates placing an order. Before creating an order, it checks product availability from a free public API (https://fakestoreapi.com). If the product is available, the order is saved in an in-memory H2 database.
- 📦 Fetch product details from a 3rd-party API (with RestTemplate)
- ✅ Place an order if the product is available
- ❌ Return "Product not available" if out of stock
- 💾 Save order data into H2 in-memory DB
- 🔁 Uses
RestTemplatefor HTTP calls - 🔧 Clean separation between Controller and Service layers
⚠️ Simple exception handling
- APIs on Swagger
- Postman Request
- H2 DB console
- Java 17+
- Spring Boot 3.x
- Spring Web
- Spring Data JPA
- H2 Database
- Lombok (optional)
- Springdoc OpenAPI (Swagger UI)
mvn spring-boot:run
POST /api/orders?productId=1&quantity=2
GET /api/orders?page=0&size=5
GET http://localhost:8080/api/ai/ask?prompt=Tell me a joke
📦 Sample JSON Response
✅ Success{
"id": 1,
"productId": 1,
"productName": "Fjallraven - Foldsack No. 1 Backpack",
"price": 109.95,
"createdAt": "2025-08-24T13:45:21.123"
}
❌ Product Not Available Product not available.
❌ Invalid ID or API Error Error occurred: 404 Not Found
http://localhost:8080/swagger-ui.html
This project is licensed under the MIT License.
If you have some query, feel free to connect with me here -- Ranjan Kumar Mandal



