The Cart API persists each user’s cart server-side inside their MongoDB user document. All three endpoints require authentication — pass the JWT token in theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/bhavnesh7781/Food-Delivery-App/llms.txt
Use this file to discover all available pages before exploring further.
token request header. The cart is stored as a flat map on the user document under the key cartData, where each key is a food item’s _id and the value is its integer quantity:
You do not need to send
userId in any request body. The auth middleware automatically decodes it from your JWT token and injects it into the request before the controller runs.POST /api/cart/add
Adds one unit of a food item to the authenticated user’s cart. If the item is not yet in the cart, it is initialized with a quantity of1. If it already exists, the quantity is incremented by 1.
Request Headers
A valid JWT token issued at login. The middleware decodes this to extract
userId.Request Body
The MongoDB
_id of the food item to add (e.g., "6641a3f2e4b0c123456789ab").Response
true when the cart was updated successfully."Added to cart" on success, "Error" on failure.Example
POST /api/cart/remove
Removes one unit of a food item from the authenticated user’s cart. The quantity is decremented by1 only if the current quantity is greater than 0. This prevents the quantity from going negative.
Request Headers
A valid JWT token issued at login.
Request Body
The MongoDB
_id of the food item to decrement.Response
true when the cart was updated successfully."Removed from cart" on success, "Error" on failure.Example
POST /api/cart/get
Retrieves the full cart map for the authenticated user. The frontend uses this response to re-hydrate the cart state on page load or after a refresh.Request Headers
A valid JWT token issued at login.
Request Body
Send an empty JSON object —userId is provided by the auth middleware.
Response
true when the cart data was fetched successfully.A key-value map of food item IDs to their quantities. Each key is a MongoDB
_id string and each value is a non-negative integer representing how many units are in the cart. Items with a quantity of 0 may still appear in the map after being decremented.