Gen-Endpoint

Free Shopping Cart API — Mock REST API for Testing & Development

E-commerce
7 Endpoints
Live & Active

Stateful shopping carts are complex to mock purely in local storage. The Shopping Cart API provides session-aware endpoints where frontend apps can create carts (POST /api/cart/{sessionId}), add line items, adjust quantities, and calculate subtotal/tax totals automatically with live JSON responses.

Internal API - Hosted by Gen-Endpoint

Interactive Live API Explorer

Explore, configure parameters, and execute live HTTP requests directly in your browser. All routes are active!
GET

/api/cart/{sessionId}

Get cart contents for session. Creates a new cart if sessionId is new or cart expired. Replace {sessionId} with an ID (e.g., sess_123).

Try it live in browser

Replace placeholders (e.g., {userId}) with actual values in the path above. You can also add/edit query parameters (e.g., ?key=value).

POST

/api/cart/{sessionId}/items

Add an item to the cart. Replace {sessionId} with a session ID.

Try it live in browser

Replace placeholders (e.g., {userId}) with actual values in the path above.

GET

/api/cart/{sessionId}/items

List all items in the specified cart. Replace {sessionId} with a session ID.

Try it live in browser

Replace placeholders (e.g., {userId}) with actual values in the path above. You can also add/edit query parameters (e.g., ?key=value).

PUT

/api/cart/{sessionId}/items

Update quantity of an item in the cart. Expects itemId and new quantity. Replace {sessionId} with a session ID.

Try it live in browser

Replace placeholders (e.g., {userId}) with actual values in the path above.

DELETE

/api/cart/{sessionId}/items

Remove an item from the cart. Expects itemId. Replace {sessionId} with a session ID.

Try it live in browser

Replace placeholders (e.g., {userId}) with actual values in the path above.

PUT

/api/cart/{sessionId}

Update cart metadata, e.g., apply a coupon code. Replace {sessionId} with a session ID.

Try it live in browser

Replace placeholders (e.g., {userId}) with actual values in the path above.

DELETE

/api/cart/{sessionId}

Clear all items from the cart (cart session persists but is empty). Replace {sessionId} with a session ID.

Try it live in browser

Replace placeholders (e.g., {userId}) with actual values in the path above.

Code Integration Examples

Copy ready-to-use cURL commands and JavaScript Fetch snippets directly into your projects or testing tools.
Standard Fetch API (Browser & Node.js 18+)
// Free Shopping Cart API - JavaScript Fetch Example
async function fetchShoppingCartAPI() {
  try {
    const response = await fetch('https://gen-endpoint.com/api/cart/{sessionId}', {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const data = await response.json();
    console.log('Success:', data);
    return data;
  } catch (error) {
    console.error('Fetch error:', error);
  }
}

fetchShoppingCartAPI();

Sample JSON Response

{
  "id": "sess_123",
  "userId": null,
  "items": [
    {
      "id": "item_abc",
      "productId": "prod_123",
      "name": "Wireless Headphones",
      "priceAtTimeOfAddition": 99.99,
      "quantity": 1,
      "imageUrl": "https://placehold.co/100x100.png",
      "options": {
        "color": "black"
      },
      "subtotal": 99.99
    }
  ],
  "subtotal": 99.99,
  "tax": 8,
  "shipping": 0,
  "discount": 0,
  "total": 107.99,
  "createdAt": "2024-08-20T10:00:00Z",
  "updatedAt": "2024-08-20T10:05:00Z",
  "expiresAt": "2024-08-21T10:00:00Z"
}

Common Developer Use Cases

How developers integrate the Shopping Cart API during rapid frontend prototyping and automated testing.

Testing add-to-cart animations, flyout cart drawers, and badge counters.

Validating quantity increment/decrement debouncing and total price updates.

Testing multi-step checkout transitions with existing cart sessions.

Testing empty cart states and promo code application workflows.

Related Free REST APIs

Explore complementary mock endpoints to chain and test full application workflows.

Product Catalog API

E-commerce

API for browsing and managing a product catalog.

View API

Payment Processing API

E-commerce

Handle payment flows, refunds, and transaction history with multiple payment methods.

View API

Inventory Management API

E-commerce

Track stock levels, handle reservations, manage warehouses, and process stock adjustments.

View API

Authentication API

Security

Simplified API for user authentication processes like login, logout, and status check.

View API

Frequently Asked Questions

How is the cart session identified?

Pass any unique string in the path, e.g., /api/cart/user-session-123. The API will maintain that session's cart items.

Does the cart calculate order totals automatically?

Yes, the response calculates subtotal, tax, and grand total based on the line item prices and quantities.

Can I remove items or clear the entire cart?

Yes, call DELETE /api/cart/{sessionId}/items to remove a specific item or DELETE /api/cart/{sessionId} to clear the entire cart.