Basket API Reference
Complete REST API documentation for the Basket service endpoints.Base URL
Endpoints
GET /basket/
Retrieve a shopping cart for a specific user.Parameters
| Name | Type | Location | Required | Description |
|---|---|---|---|---|
| userName | string | path | Yes | The username identifying the basket |
Response
Status Code:200 OK
Response Body:
Error Responses
Status Code:400 Bad Request
404 Not Found
Example Request
POST /basket
Create or update a shopping cart. Automatically applies discounts via gRPC communication with Discount service.Request Body
Request Schema
Response
Status Code:201 Created
Headers:
Discount Application
The service automatically applies discounts before storing:- For each item in the cart, calls Discount.Grpc service
- Retrieves coupon for the product by name
- Deducts the discount amount from item price
- Stores the discounted prices
StoreBasketHandler.cs:30-38):
Validation Rules
Cartmust not be nullCart.UserNamemust not be empty
Error Responses
Status Code:400 Bad Request
Example Request
DELETE /basket/
Delete a shopping cart for a specific user. Removes from both database and cache.Parameters
| Name | Type | Location | Required | Description |
|---|---|---|---|---|
| userName | string | path | Yes | The username identifying the basket to delete |
Response
Status Code:200 OK
Response Body:
Validation Rules
UserNamemust not be empty
Error Responses
Status Code:400 Bad Request
404 Not Found
Example Request
POST /basket/checkout
Checkout a shopping basket. Publishes checkout event to message broker and deletes the basket.Request Body
Request Schema
Response
Status Code:200 OK
Response Body:
Checkout Process
The checkout operation performs the following steps (CheckoutBasketHandler.cs:25-46):
- Retrieve Basket: Fetches existing basket with calculated total price
- Create Event: Maps checkout DTO to
BasketCheckoutEvent - Set Total: Adds calculated total price to event
- Publish Event: Sends event to RabbitMQ via MassTransit
- Delete Basket: Removes basket from storage and cache
Event Publishing
TheBasketCheckoutEvent triggers downstream processes:
- Order creation in Ordering service
- Payment processing
- Inventory updates
- Email notifications
Validation Rules
BasketCheckoutDtomust not be nullBasketCheckoutDto.UserNamemust not be empty
Error Responses
Status Code:400 Bad Request
Example Request
Health Check
GET /health
Check the health status of the Basket service and its dependencies.Response
Status Code:200 OK (Healthy) or 503 Service Unavailable (Unhealthy)
Response Body:
