API Documentation

Authentication

Before accessing any of the data endpoints, you need to authenticate and obtain a JWT token.

POST /api/auth

Request:

{
  "username": "student",
  "password": "password123"
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Error Response (401):

{
  "error": "Invalid credentials"
}

Using the Token

For all other API endpoints, you must include the token in the Authorization header:

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Available Endpoints

Users

GET /api/users

Returns a list of all users.

GET /api/users?id=1

Returns a specific user by ID.

Products

GET /api/products

Returns a list of all products.

GET /api/products?id=1

Returns a specific product by ID.

GET /api/products?category=Electronics

Returns all products in a specific category.

POST /api/products/create

Creates a new product.

Request:
{
  "name": "New Product",
  "price": 199.99,
  "category": "Electronics",
  "stock": 10
}
Response (201):
{
  "message": "Product created successfully",
  "product": {
    "id": 123,
    "name": "New Product",
    "price": 199.99,
    "category": "Electronics",
    "stock": 10
  }
}