The Spring Boot application is running on http://localhost:8080 with H2 in-memory database.
Run the comprehensive test script:
./api-test.shThis script will test all major endpoints automatically.
- Import the
B2C-Ecommerce-API.postman_collection.jsonfile into Postman - The collection includes all endpoints with proper authentication
- Run the requests in sequence (Authentication → Categories → Products → etc.)
Here are some key cURL commands to test the API:
# Register a customer
curl -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "customer@example.com",
"password": "password123",
"role": "CUSTOMER",
"firstName": "John",
"lastName": "Doe",
"phone": "+1234567890"
}'
# Login as customer
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "customer@example.com",
"password": "password123"
}'# Create a category (requires vendor token)
curl -X POST http://localhost:8080/api/categories \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_VENDOR_TOKEN" \
-d '{
"name": "Electronics",
"description": "Electronic devices and accessories",
"imageUrl": "https://example.com/electronics.jpg"
}'
# Get all categories
curl -X GET http://localhost:8080/api/categories# Create a product (requires vendor token)
curl -X POST http://localhost:8080/api/products \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_VENDOR_TOKEN" \
-d '{
"name": "Smartphone",
"description": "Latest smartphone model",
"price": 599.99,
"stockQuantity": 50,
"categoryId": 1,
"images": "[\"https://example.com/phone1.jpg\", \"https://example.com/phone2.jpg\"]"
}'
# Get all products
curl -X GET http://localhost:8080/api/products# Add item to cart (requires customer token)
curl -X POST http://localhost:8080/api/cart/items \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_CUSTOMER_TOKEN" \
-d '{
"productId": 1,
"quantity": 2
}'
# Get cart
curl -X GET http://localhost:8080/api/cart \
-H "Authorization: Bearer YOUR_CUSTOMER_TOKEN"# Create an order (requires customer token)
curl -X POST http://localhost:8080/api/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_CUSTOMER_TOKEN" \
-d '{
"shippingAddressId": 1
}'
# Get customer orders
curl -X GET http://localhost:8080/api/orders \
-H "Authorization: Bearer YOUR_CUSTOMER_TOKEN"Access the H2 database console to view data:
- URL:
http://localhost:8080/h2-console - JDBC URL:
jdbc:h2:mem:testdb - Username:
sa - Password: (leave empty)
- Register a user (customer or vendor)
- Login to get a JWT token
- Use the token in the
Authorization: Bearer <token>header for protected endpoints
{
"success": true,
"message": "Operation successful",
"data": { ... }
}{
"success": false,
"message": "Error description",
"timestamp": "2024-01-01T00:00:00",
"path": "/api/endpoint"
}- Register as customer
- Login to get token
- Browse products
- Add items to cart
- Create shipping address
- Place order
- Add review
- Register as vendor
- Login to get token
- Create categories
- Add products
- View orders
- Update order status
- View all users
- Verify vendors
- Manage system
- 401 Unauthorized: Check if you're using a valid JWT token
- 403 Forbidden: Check if you have the correct role for the endpoint
- 404 Not Found: Check if the endpoint URL is correct
- 500 Internal Server Error: Check server logs for details
To enable debug logging, add to application.yml:
logging:
level:
com.example.b2c: DEBUG
org.springframework.security: DEBUG| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/auth/register |
Register user | No |
| POST | /api/auth/login |
Login user | No |
| GET | /api/auth/profile |
Get user profile | Yes |
| GET | /api/categories |
Get all categories | No |
| POST | /api/categories |
Create category | Vendor |
| GET | /api/products |
Get all products | No |
| POST | /api/products |
Create product | Vendor |
| GET | /api/cart |
Get cart | Customer |
| POST | /api/cart/items |
Add to cart | Customer |
| POST | /api/orders |
Create order | Customer |
| GET | /api/orders |
Get orders | Customer |
| POST | /api/reviews |
Create review | Customer |
| POST | /api/price-quotes/upload |
Upload quote | Customer |
- Test all endpoints using the provided methods
- Check the H2 console to verify data persistence
- Integrate with your React frontend
- Set up MySQL database for production
- Configure proper JWT secrets and database credentials
- GET
/api/products: Search and filter products.- Params:
keyword(string),categoryId(long),page(int),size(int),sort(string) - Access: Public
- Params:
- GET
/api/products/{id}: Get a single product by its ID.- Access: Public
- POST
/api/products: Create a new product.- Access: Vendor, Admin
- Body:
ProductRequestDTO. If the user is an admin,vendorIdmust be provided.
- PUT
/api/products/{id}: Update an existing product.- Access: Vendor (own products), Admin
- DELETE
/api/products/{id}: Delete a product.- Access: Vendor (own products), Admin
- POST
/api/orders/checkout: Create an order from the user's cart.- Access: Customer
- Body:
OrderRequestDTO containingshippingAddressId.
- GET
/api/orders/my-orders: Get the currently authenticated customer's order history.- Access: Customer
- GET
/api/orders: Get all orders in the system (paginated).- Access: Admin
- GET
/api/reports/vendor/sales: Generate a sales report for the currently authenticated vendor.- Access: Vendor
- Response: A map containing
totalRevenueandtotalOrders.