Products
Browse, search, and filter products available in the e-commerce catalog.
List Products
GET /api/ecom/producto Get paginated list of products with optional filters
Retrieve a paginated list of public products with optional filtering by search query, category, and price range.
Query Parameters
Search query to filter products by name or description
Category filter to show products from specific category
Minimum price filter (inclusive)
Maximum price filter (inclusive)
Page number for pagination (starts at 1)
The page limit is controlled by the PAGINATION_LIMIT environment variable (default: 20 items per page).
Response
Array of product objects Show Product object properties
Product unique identifier
Product image URL or path
Pagination metadata Show Pagination properties
Total number of products matching filters
Total number of pages available
Example Requests
Basic List
Search Query
Category Filter
Price Range
Combined Filters
JavaScript
Python
curl -X GET "https://api.example.com/api/ecom/producto?page=1"
Example Response
{
"data" : [
{
"prd_codigo" : "PRD001" ,
"prd_nombre" : "Laptop Gaming MSI" ,
"prd_descripcion" : "Laptop gaming de alto rendimiento con RTX 4060" ,
"prd_precio" : 1299.99 ,
"prd_stock" : 15 ,
"cat_nombre" : "Electronics" ,
"prd_imagen" : "/images/products/laptop-msi.jpg"
},
{
"prd_codigo" : "PRD002" ,
"prd_nombre" : "Laptop Dell XPS 15" ,
"prd_descripcion" : "Laptop profesional con pantalla 4K" ,
"prd_precio" : 1499.99 ,
"prd_stock" : 8 ,
"cat_nombre" : "Electronics" ,
"prd_imagen" : "/images/products/laptop-dell.jpg"
}
],
"pagination" : {
"page" : 1 ,
"limit" : 20 ,
"totalCount" : 42 ,
"totalPages" : 3
}
}
The total_count field from the database window function is automatically removed from individual product objects to keep the response clean.
Get Product Details
GET /api/ecom/producto/:id Get detailed information about a specific product
Retrieve complete details for a single product by its ID.
Path Parameters
Product unique identifier (prd_codigo)
Response
Complete product information Product unique identifier
Detailed product description
Product image URL or path
Whether product is active/available
Example Requests
curl -X GET "https://api.example.com/api/ecom/producto/PRD001"
Example Response
{
"prd_codigo" : "PRD001" ,
"prd_nombre" : "Laptop Gaming MSI" ,
"prd_descripcion" : "Laptop gaming de alto rendimiento con procesador Intel Core i7, 16GB RAM, RTX 4060, SSD 512GB. Pantalla 15.6 \" 144Hz. Ideal para gaming y trabajo profesional." ,
"prd_precio" : 1299.99 ,
"prd_stock" : 15 ,
"cat_codigo" : "CAT001" ,
"cat_nombre" : "Electronics" ,
"prd_imagen" : "/images/products/laptop-msi.jpg" ,
"prd_activo" : true
}
{
"message" : "Producto no encontrado"
}
Product Filtering
The product list endpoint supports multiple filters that can be combined:
Search Query (q)
Filters products by name or description. The search is typically case-insensitive and may support partial matches.
GET /api/ecom/producto?q=laptop
Category Filter (cat)
Filters products by category code or name.
GET /api/ecom/producto?cat=electronics
Price Range
Filter products within a specific price range using minPrice and maxPrice parameters.
GET /api/ecom/producto?minPrice= 500 & maxPrice = 2000
Price filters are inclusive, meaning products with prices equal to minPrice or maxPrice will be included in results.
Combining Filters
All filters can be combined for more specific searches:
GET /api/ecom/producto?q=gaming & cat = electronics & minPrice = 1000 & maxPrice = 2000 & page = 1
Product listings are paginated to improve performance and user experience.
Default limit: 20 products per page (configurable via PAGINATION_LIMIT)
Pages start at 1 (not 0)
The response includes pagination metadata
Empty results return an empty array with pagination info
Each list response includes:
"pagination" : {
"page" : 1 , // Current page
"limit" : 20 , // Items per page
"totalCount" : 42 , // Total products matching filters
"totalPages" : 3 // Total pages available
}
Example: Fetching All Pages
async function getAllProducts () {
const products = [];
let page = 1 ;
let hasMore = true ;
while ( hasMore ) {
const response = await fetch (
`https://api.example.com/api/ecom/producto?page= ${ page } `
);
const data = await response . json ();
products . push ( ... data . data );
hasMore = page < data . pagination . totalPages ;
page ++ ;
}
return products ;
}
Error Handling
Common Error Responses
500 Internal Server Error
{
"message" : "Error al obtener productos"
}
404 Not Found (Single Product)
{
"message" : "Producto no encontrado"
}
If an invalid page number is provided (e.g., page 99 when only 3 pages exist), the API will return an empty data array with the correct pagination metadata.
Use Cases
Storefront Product Listing
Display products on your e-commerce homepage:
const response = await fetch ( 'https://api.example.com/api/ecom/producto?page=1' );
const { data : products , pagination } = await response . json ();
// Display products in grid
products . forEach ( product => {
displayProduct ( product );
});
// Show pagination controls
showPagination ( pagination );
Product Search
Implement search functionality:
const searchTerm = 'laptop' ;
const response = await fetch (
`https://api.example.com/api/ecom/producto?q= ${ encodeURIComponent ( searchTerm ) } `
);
const { data : results } = await response . json ();
Category Browsing
Show products from specific category:
const category = 'electronics' ;
const response = await fetch (
`https://api.example.com/api/ecom/producto?cat= ${ category } &page=1`
);
const { data : categoryProducts } = await response . json ();
Product Detail Page
Show detailed product information:
const productId = 'PRD001' ;
const response = await fetch (
`https://api.example.com/api/ecom/producto/ ${ productId } `
);
const product = await response . json ();
// Display product details, add to cart button, etc.
Source Code Reference
Implementation details can be found in:
Routes: /src/routes/ecom.producto.routes.js:5-10
Controller: /src/controllers/ecom.producto.controller.js:6-72
Model: /src/models/ecom.producto.model.js
Products displayed through this API are filtered to show only public/active products. Internal or inactive products are not exposed through the e-commerce endpoints.