Skip to content

Latest commit

 

History

History
270 lines (222 loc) · 4.64 KB

File metadata and controls

270 lines (222 loc) · 4.64 KB

E-Commerce API Documentation

Base URL

http://localhost:5000/api

Authentication

Authentication uses JWT tokens. Include the token in the Authorization header:

Authorization: Bearer <access_token>

Endpoints

Auth Routes (/auth)

Register User

  • POST /auth/register
  • Body:
    {
      "name": "string",
      "email": "string",
      "password": "string"
    }
  • Response: User object with accessToken and refreshToken

Login

  • POST /auth/login
  • Body:
    {
      "email": "string",
      "password": "string"
    }
  • Response: User object with accessToken and refreshToken

Refresh Token

  • POST /auth/refresh
  • Body:
    {
      "refreshToken": "string"
    }
  • Response: New accessToken

Get Current User

  • GET /auth/me
  • Auth: Required
  • Response: Current user object

Product Routes (/products)

Get All Products

  • GET /products
  • Query Parameters:
    • category (optional): Filter by category
    • page (optional): Page number (default: 1)
    • limit (optional): Items per page (default: 20)
  • Response: Array of product objects

Get Single Product

  • GET /products/:id
  • Response: Product object with reviews

Create Product

  • POST /products
  • Auth: Required (Admin only)
  • Body:
    {
      "name": "string",
      "description": "string",
      "price": "number",
      "stock": "number",
      "category": "string",
      "images": ["string"]
    }
  • Response: Created product object

Update Product

  • PUT /products/:id
  • Auth: Required (Admin only)
  • Body: Partial product object
  • Response: Updated product object

Delete Product

  • DELETE /products/:id
  • Auth: Required (Admin only)
  • Response: Success message

Cart Routes (/cart)

Get User Cart

  • GET /cart
  • Auth: Required
  • Response: Cart object with items

Add to Cart

  • POST /cart/items
  • Auth: Required
  • Body:
    {
      "productId": "string",
      "quantity": "number"
    }
  • Response: Updated cart

Update Cart Item

  • PUT /cart/items/:itemId
  • Auth: Required
  • Body:
    {
      "quantity": "number"
    }
  • Response: Updated cart

Remove from Cart

  • DELETE /cart/items/:itemId
  • Auth: Required
  • Response: Updated cart

Clear Cart

  • DELETE /cart
  • Auth: Required
  • Response: Success message

Order Routes (/orders)

Create Order

  • POST /orders
  • Auth: Required
  • Body:
    {
      "items": [
        {
          "productId": "string",
          "quantity": "number"
        }
      ],
      "address": {
        "street": "string",
        "city": "string",
        "state": "string",
        "zipCode": "string",
        "country": "string"
      }
    }
  • Response: Created order object

Get User Orders

  • GET /orders
  • Auth: Required
  • Response: Array of user orders

Get Order Details

  • GET /orders/:id
  • Auth: Required
  • Response: Order object with items

Update Order Status

  • PUT /orders/:id/status
  • Auth: Required (Admin only)
  • Body:
    {
      "status": "PENDING|PROCESSING|SHIPPED|DELIVERED|CANCELLED"
    }
  • Response: Updated order object

Review Routes (/products/:productId/reviews)

Get Product Reviews

  • GET /products/:productId/reviews
  • Response: Array of review objects

Create Review

  • POST /products/:productId/reviews
  • Auth: Required
  • Body:
    {
      "rating": "number (1-5)",
      "comment": "string"
    }
  • Response: Created review object

Update Review

  • PUT /reviews/:id
  • Auth: Required
  • Body:
    {
      "rating": "number",
      "comment": "string"
    }
  • Response: Updated review object

Delete Review

  • DELETE /reviews/:id
  • Auth: Required
  • Response: Success message

Error Responses

All errors follow this format:

{
  "success": false,
  "error": "Error message"
}

Common Status Codes

  • 200 - Success
  • 201 - Created
  • 400 - Bad Request
  • 401 - Unauthorized
  • 403 - Forbidden
  • 404 - Not Found
  • 500 - Internal Server Error

Pagination

Paginated responses include:

{
  "items": [],
  "total": 100,
  "page": 1,
  "pageSize": 20
}

Rate Limiting

  • Auth endpoints: 5 requests per minute
  • Other endpoints: 100 requests per minute

Webhooks

Stripe Webhooks

  • Event: charge.succeeded
  • Event: charge.failed
  • Endpoint: /api/webhooks/stripe

For more information, check the main README.md