Skip to main content

Overview

The Products API provides endpoints for browsing, searching, and creating products in the ShopStack catalog.

GET /api/products

Retrieve a paginated list of products.

Request

Method: GET Path: /api/products Authentication: None required Query Parameters:
page
integer
default:"1"
Page number for pagination
per_page
integer
default:"20"
Number of products per page
category
string
Filter products by category

Response

products
array
Array of product objects
products[].id
integer
Product’s unique identifier
products[].name
string
Product name
products[].description
string
Product description
products[].price
number
Product price
products[].stock
integer
Available stock quantity
products[].category
string
Product category
products[].created_at
datetime
Creation timestamp
products[].updated_at
datetime
Last update timestamp
total
integer
Total number of products matching the query
page
integer
Current page number
per_page
integer
Products per page
pages
integer
Total number of pages

Example

cURL
curl -X GET "http://localhost:5000/api/products?page=1&per_page=10&category=electronics"
Response (200 OK):
{
  "products": [
    {
      "id": 1,
      "name": "Laptop Pro 15",
      "description": "High-performance laptop with 15-inch display",
      "price": 1299.99,
      "stock": 25,
      "category": "electronics",
      "created_at": "2024-01-10T08:00:00",
      "updated_at": "2024-01-15T12:30:00"
    },
    {
      "id": 2,
      "name": "Wireless Mouse",
      "description": "Ergonomic wireless mouse",
      "price": 29.99,
      "stock": 150,
      "category": "electronics",
      "created_at": "2024-01-10T08:15:00",
      "updated_at": "2024-01-10T08:15:00"
    }
  ],
  "total": 45,
  "page": 1,
  "per_page": 10,
  "pages": 5
}

GET /api/products/<id>

Retrieve a specific product by ID.

Request

Method: GET Path: /api/products/<id> Authentication: None required Path Parameters:
id
integer
required
Product ID

Response

product
object
Product object with all details (same structure as products array above)

Example

cURL
curl -X GET http://localhost:5000/api/products/1
Response (200 OK):
{
  "product": {
    "id": 1,
    "name": "Laptop Pro 15",
    "description": "High-performance laptop with 15-inch display",
    "price": 1299.99,
    "stock": 25,
    "category": "electronics",
    "created_at": "2024-01-10T08:00:00",
    "updated_at": "2024-01-15T12:30:00"
  }
}

Error Responses

404 Not Found - Product not found:
{
  "error": "Product not found"
}

GET /api/products/search

Search for products by name or description.

Request

Method: GET Path: /api/products/search Authentication: None required Query Parameters:
q
string
required
Search query string. Searches in product name and description.

Response

products
array
Array of matching product objects
products[].id
integer
Product’s unique identifier
products[].name
string
Product name
products[].description
string
Product description
products[].price
number
Product price
products[].stock
integer
Available stock quantity
products[].category
string
Product category
count
integer
Number of products found

Example

cURL
curl -X GET "http://localhost:5000/api/products/search?q=laptop"
Response (200 OK):
{
  "products": [
    {
      "id": 1,
      "name": "Laptop Pro 15",
      "description": "High-performance laptop with 15-inch display",
      "price": 1299.99,
      "stock": 25,
      "category": "electronics"
    },
    {
      "id": 5,
      "name": "Laptop Stand",
      "description": "Adjustable laptop stand for ergonomic setup",
      "price": 49.99,
      "stock": 80,
      "category": "accessories"
    }
  ],
  "count": 2
}

Error Responses

400 Bad Request - Missing search query:
{
  "error": "Search query parameter 'q' is required"
}

POST /api/products

Create a new product.

Request

Method: POST Path: /api/products Authentication: JWT token required Headers:
  • Authorization: Bearer <access_token>
  • Content-Type: application/json
Body Parameters:
name
string
required
Product name
price
number
required
Product price
description
string
default:""
Product description
stock
integer
default:"0"
Initial stock quantity
category
string
Product category

Response

product
object
Created product object with all details

Example

cURL
curl -X POST http://localhost:5000/api/products \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Mechanical Keyboard",
    "description": "RGB mechanical gaming keyboard",
    "price": 89.99,
    "stock": 50,
    "category": "electronics"
  }'
Response (201 Created):
{
  "product": {
    "id": 10,
    "name": "Mechanical Keyboard",
    "description": "RGB mechanical gaming keyboard",
    "price": 89.99,
    "stock": 50,
    "category": "electronics",
    "created_at": "2024-01-15T14:20:00",
    "updated_at": "2024-01-15T14:20:00"
  }
}

Error Responses

400 Bad Request - Missing required field:
{
  "error": "Missing required field: name"
}
401 Unauthorized - Missing or invalid token:
{
  "msg": "Missing Authorization Header"
}

Build docs developers (and LLMs) love