Authentication

POST /api/auth/login

Authenticate a user and receive a Sanctum bearer token. Accepts either username or email.

Request Body (JSON)
Field Type Required Notes
username string optional* Required if email is omitted
email string optional* Required if username is omitted
password string required
Example Request
POST /api/auth/login
Content-Type: application/json

{
  "username": "emilys",
  "password": "emilyspass"
}
Example Response — 200 OK
{
  "id": 1,
  "username": "Emily Smith",
  "email": "emily.smith@example.com",
  "firstName": "Emily",
  "lastName": "Smith",
  "role": "admin",
  "token": "1|abc123..."
}
POST /api/users/add

Register a new user account. Returns the created user without a token.

Request Body (JSON)
Field Type Required Notes
firstName string required max 255 chars
lastName string required max 255 chars
email string required must be unique
password string required min 6 chars
Example Response — 201 Created
{
  "id": 42,
  "username": "Jane Doe",
  "email": "jane.doe@example.com",
  "firstName": "Jane",
  "lastName": "Doe",
  "role": "user"
}
GET /api/auth/me Auth required

Returns the currently authenticated user's profile.

Headers
Header Value
Authorization Bearer <token>
Example Response — 200 OK
{
  "id": 1,
  "username": "Emily Smith",
  "email": "emily.smith@example.com",
  "firstName": "Emily",
  "lastName": "Smith",
  "role": "admin"
}
POST /api/auth/logout Auth required

Revokes the current bearer token (logs the user out).

Headers
Header Value
Authorization Bearer <token>
Example Response — 200 OK
{
  "message": "Logged out successfully."
}

Products

GET /api/products

Returns a paginated list of products. Supports full-text search and offset pagination.

Query Parameters
Parameter Type Default Description
limit integer 30 Number of products to return
skip integer 0 Number of products to skip (offset)
q string Search term matched against title and description
Example Request
GET /api/products?limit=10&skip=0&q=laptop
Example Response — 200 OK
{
  "products": [
    {
      "id": 1,
      "title": "Laptop Pro",
      "description": "High-performance laptop",
      "category": "laptops",
      "price": 999.99,
      "discountPercentage": 10,
      "rating": 4.5,
      "stock": 25,
      "brand": "TechBrand",
      "thumbnail": "https://example.com/thumb.jpg",
      "images": ["https://example.com/img1.jpg"]
    }
  ],
  "total": 1,
  "skip": 0,
  "limit": 10
}
GET /api/products/{id}

Returns a single product by its ID.

Path Parameters
Parameter Type Description
id integer Product ID
Example Request
GET /api/products/1
Example Response — 200 OK
{
  "id": 1,
  "title": "Laptop Pro",
  "description": "High-performance laptop",
  "category": "laptops",
  "price": 999.99,
  "discountPercentage": 10,
  "rating": 4.5,
  "stock": 25,
  "brand": "TechBrand",
  "thumbnail": "https://example.com/thumb.jpg",
  "images": ["https://example.com/img1.jpg"]
}
POST /api/products/add Admin only

Creates a new product. Requires a valid admin bearer token.

Headers
Header Value
Authorization Bearer <admin-token>
Content-Type application/json
Request Body (JSON)
Field Type Required Notes
title string required max 255 chars
description string required
category string required max 100 chars
price number required min 0
thumbnail string required URL string
discountPercentage number optional 0–100
rating number optional 0–5
stock integer optional min 0
brand string optional max 100 chars
images array optional array of URL strings
Example Response — 201 Created
{
  "id": 101,
  "title": "New Product",
  "category": "electronics",
  "price": 49.99,
  ...
}
PUT /api/products/{id} Admin only

Updates an existing product. Only included fields are changed.

Path Parameters
Parameter Type Description
id integer Product ID to update
Request Body (JSON) — all fields optional
Field Type Notes
title string max 255 chars
description string
category string max 100 chars
price number min 0
thumbnail string URL string
discountPercentage number 0–100
rating number 0–5
stock integer min 0
brand string max 100 chars
images array array of URL strings
Example Response — 200 OK
{
  "id": 1,
  "title": "Updated Title",
  "price": 79.99,
  ...
}
DELETE /api/products/{id} Admin only

Permanently deletes the specified product.

Path Parameters
Parameter Type Description
id integer Product ID to delete
Example Response — 200 OK
{
  "isDeleted": true,
  "id": 1,
  "deletedOn": "2026-03-22T12:00:00.000000Z"
}