Real World Example

An Order Flow Like Swiggy or Flipkart

When you tap "Place Order" in a shopping app, the app makes a few REST calls in sequence. The ShopEase version:

1. GET    /api/products?category=electronics   -> 200 OK        (browse)
 2. POST   /api/cart       {"productId":1,"quantity":2}  -> 201 Created
 3. GET    /api/cart                             -> 200 OK        (review cart)
 4. POST   /api/orders                           -> 201 Created  Location: /api/orders/101
 5. GET    /api/orders/101                       -> 200 OK        {"status":"PLACED"}

The Same Calls with curl

Example

curl sends HTTP requests from a terminal; -i shows the status line and headers. (This is the API you will build across the Spring Boot levels.)

curl -i -X POST http://localhost:8080/api/orders \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \
     -d '{"items":[{"productId":1,"quantity":2}],"paymentMode":"UPI"}'

Example output

HTTP/1.1 201 Created
Location: /api/orders/101
Content-Type: application/json

{"id":101,"status":"PLACED","total":2998.00,"items":[{"productId":1,"name":"Boat Rockerz 450","quantity":2,"price":1499.00}]}

ShopEase API Map

MethodURLSuccessTypical errors
GET/api/products200-
GET/api/products/{id}200404
POST/api/cart201400, 401, 409 (out of stock)
POST/api/orders201400, 401, 402/409 (payment / stock)
DELETE/api/cart/{itemId}204401, 404