Skip to main content
GET
/
search
Search Products
curl --request GET \
  --url https://api.example.com/search
{
  "products": [
    {
      "_id": "<string>",
      "brand": "<string>",
      "name": "<string>",
      "stock": 123,
      "price": 123,
      "normalizedName": "<string>"
    }
  ]
}
Searches for products by name using a normalized text search.

Authentication

This endpoint requires authentication. Include a valid JWT token in the Authorization header.

Query Parameters

q
string
The search query string to match against product names. If not provided, returns an empty string search.

Response

products
array
Array of products matching the search query
_id
string
Unique identifier for the product
brand
string
The product brand
name
string
The product name
stock
number
The quantity in stock
price
number
The product price
normalizedName
string
Normalized version of the product name used for search matching

Status Codes

  • 200: Search completed successfully
  • 404: No products found matching the search query
  • 401: Authentication token missing or invalid
  • 500: Server error

Example Request

curl "http://localhost:3000/search?q=mouse" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Example Response

{
  "products": [
    {
      "_id": "507f1f77bcf86cd799439011",
      "brand": "TechCorp",
      "name": "Wireless Mouse",
      "stock": 150,
      "price": 29.99,
      "normalizedName": "wireless mouse"
    },
    {
      "_id": "507f1f77bcf86cd799439013",
      "brand": "GameTech",
      "name": "Gaming Mouse RGB",
      "stock": 85,
      "price": 59.99,
      "normalizedName": "gaming mouse rgb"
    }
  ]
}

Error Response (404)

{
  "message": "⚠️ No se encontraron productos..."
}

Error Response (500)

{
  "message": "❌ Error al buscar productos...",
  "error": "Search query failed"
}

Build docs developers (and LLMs) love