Sample of API Documentation for Inventory Management System

1. Authentication Register User Endpoint: POST /api/auth/register Description: Registers a new user. Request Body: { "name": "John Doe", "email": "john@example.com", "password": "password123" } Response: { "message": "User registered successfully", "user": { "id": "123", "name": "John Doe", "email": "john@example.com" } } User Login Endpoint: POST /api/auth/login Description: Logs in a user. Request Body: { "email": "john@example.com", "password": "password123" } Response: { "token": "jwt-token-here" } 2. Products Get All Products Endpoint: GET /api/products Description: Fetch all available products. Response: [ { "id": "1", "name": "Laptop", "description": "Gaming Laptop", "price": 1200, "stock": 10, "category": "Electronics" } ] Add New Product Endpoint: POST /api/products Description: Adds a new product (Admin Only). Request Body: { "name": "Laptop", "description": "Gaming Laptop", "price": 1200, "stock": 10, "category": "Electronics" } Response: { "message": "Product added successfully", "product": { "id": "1", "name": "Laptop" } } 3. Orders Place an Order Endpoint: POST /api/orders Description: Places a new order. Request Body: { "userId": "123", "products": [ { "productId": "1", "quantity": 2 } ], "totalPrice": 2400 } Response: { "message": "Order placed successfully", "orderId": "456" } Get User Orders Endpoint: GET /api/orders/{userId} Description: Fetches all orders placed by a user. Response: [ { "id": "456", "userId": "123", "products": [ { "productId": "1", "quantity": 2 } ], "totalPrice": 2400, "status": "pending" } ] 4. Payments Process Payment Endpoint: POST /api/payments Description: Processes a payment for an order. Request Body: { "orderId": "456", "amount": 2400, "method": "bKash" } Response: { "message": "Payment successful", "paymentId": "789" }

Feb 10, 2025 - 16:47
 0
Sample of API Documentation for Inventory Management System

1. Authentication

Register User

Endpoint: POST /api/auth/register

  • Description: Registers a new user.
  • Request Body:
  {
    "name": "John Doe",
    "email": "john@example.com",
    "password": "password123"
  }
  • Response:
  {
    "message": "User registered successfully",
    "user": { "id": "123", "name": "John Doe", "email": "john@example.com" }
  }

User Login

Endpoint: POST /api/auth/login

  • Description: Logs in a user.
  • Request Body:
  {
    "email": "john@example.com",
    "password": "password123"
  }
  • Response:
  {
    "token": "jwt-token-here"
  }

2. Products

Get All Products

Endpoint: GET /api/products

  • Description: Fetch all available products.
  • Response:
  [
    {
      "id": "1",
      "name": "Laptop",
      "description": "Gaming Laptop",
      "price": 1200,
      "stock": 10,
      "category": "Electronics"
    }
  ]

Add New Product

Endpoint: POST /api/products

  • Description: Adds a new product (Admin Only).
  • Request Body:
  {
    "name": "Laptop",
    "description": "Gaming Laptop",
    "price": 1200,
    "stock": 10,
    "category": "Electronics"
  }
  • Response:
  {
    "message": "Product added successfully",
    "product": { "id": "1", "name": "Laptop" }
  }

3. Orders

Place an Order

Endpoint: POST /api/orders

  • Description: Places a new order.
  • Request Body:
  {
    "userId": "123",
    "products": [
      { "productId": "1", "quantity": 2 }
    ],
    "totalPrice": 2400
  }
  • Response:
  {
    "message": "Order placed successfully",
    "orderId": "456"
  }

Get User Orders

Endpoint: GET /api/orders/{userId}

  • Description: Fetches all orders placed by a user.
  • Response:
  [
    {
      "id": "456",
      "userId": "123",
      "products": [
        { "productId": "1", "quantity": 2 }
      ],
      "totalPrice": 2400,
      "status": "pending"
    }
  ]

4. Payments

Process Payment

Endpoint: POST /api/payments

  • Description: Processes a payment for an order.
  • Request Body:
  {
    "orderId": "456",
    "amount": 2400,
    "method": "bKash"
  }
  • Response:
  {
    "message": "Payment successful",
    "paymentId": "789"
  }