Skip to main content

Featured Items API Endpoints

The Featured Items API provides a public endpoint for retrieving featured items displayed on the website. Featured items are managed through the admin panel and stored in the database with support for ordering, activation, and expiration dates.

Source: template/app/api/featured-items/route.ts


Returns a list of active featured items for public display. Automatically filters out inactive and (optionally) expired items.

PropertyValue
MethodGET
Path/api/featured-items
AuthNone (public)

Query Parameters

ParameterTypeRequiredDefaultDescription
limitintegerNo6Maximum number of featured items to return (1-50)
includeExpiredbooleanNofalseWhether to include items past their featured_until date

Response

Status 200 -- Featured items retrieved successfully.

{
"success": true,
"data": [
{
"id": "featured_123abc",
"itemSlug": "awesome-productivity-tool",
"itemName": "Awesome Productivity Tool",
"itemDescription": "Boost your productivity with this amazing tool",
"itemIconUrl": "https://example.com/icons/tool.png",
"itemImageUrl": "https://example.com/featured/tool-banner.jpg",
"featuredOrder": 10,
"isActive": true,
"featuredAt": "2024-01-20T10:30:00.000Z",
"featuredUntil": "2024-02-20T10:30:00.000Z",
"createdAt": "2024-01-20T10:30:00.000Z",
"updatedAt": "2024-01-20T10:30:00.000Z"
}
],
"count": 1
}

Response Fields

FieldTypeDescription
dataarrayArray of featured item objects
countnumberNumber of featured items returned
data[].idstringFeatured item record ID
data[].itemSlugstringItem slug identifier
data[].itemNamestringItem display name
data[].itemDescriptionstring | nullFeatured item description
data[].itemIconUrlstring | nullItem icon URL
data[].itemImageUrlstring | nullFeatured banner image URL
data[].featuredOrdernumberDisplay order (higher = more prominent)
data[].isActivebooleanWhether the item is currently featured
data[].featuredAtstring (ISO 8601)When the item was featured
data[].featuredUntilstring | null (ISO 8601)Expiration date (null = no expiration)
data[].createdAtstring (ISO 8601)Record creation timestamp
data[].updatedAtstring | null (ISO 8601)Last update timestamp

Sorting

Items are sorted by:

  1. featuredOrder descending (highest order first)
  2. featuredAt descending (most recently featured first)

Filtering Logic

The endpoint applies these filters:

  1. Active only: Only items with isActive = true are returned.
  2. Expiration check (when includeExpired is false):
    • Items with featuredUntil = null are always included (no expiration).
    • Items with featuredUntil >= current date are included (not yet expired).
    • Items with featuredUntil < current date are excluded.

Error Response

Status 500

{
"success": false,
"error": "Failed to fetch featured items"
}

curl Examples

# Get default featured items (top 6, exclude expired)
curl -s http://localhost:3000/api/featured-items

# Get top 3 featured items
curl -s "http://localhost:3000/api/featured-items?limit=3"

# Include expired featured items
curl -s "http://localhost:3000/api/featured-items?includeExpired=true"

# Combine parameters
curl -s "http://localhost:3000/api/featured-items?limit=10&includeExpired=true"

TypeScript Usage

interface FeaturedItem {
id: string;
itemSlug: string;
itemName: string;
itemDescription: string | null;
itemIconUrl: string | null;
itemImageUrl: string | null;
featuredOrder: number;
isActive: boolean;
featuredAt: string;
featuredUntil: string | null;
createdAt: string;
updatedAt: string | null;
}

interface FeaturedItemsResponse {
success: boolean;
data: FeaturedItem[];
count: number;
}

async function getFeaturedItems(
limit: number = 6,
includeExpired: boolean = false
): Promise<FeaturedItemsResponse> {
const params = new URLSearchParams({
limit: limit.toString(),
...(includeExpired && { includeExpired: 'true' }),
});
const res = await fetch(`/api/featured-items?${params}`);
return res.json();
}

// Usage
const { data: featuredItems, count } = await getFeaturedItems(6);
featuredItems.forEach(item => {
console.log(`${item.itemName} (order: ${item.featuredOrder})`);
if (item.featuredUntil) {
console.log(` Expires: ${item.featuredUntil}`);
}
});

Implementation Notes

  • Database availability is checked at the start via checkDatabaseAvailability().
  • The limit parameter is parsed from the query string with a default of 6. Input beyond 50 is not clamped (validated client-side).
  • Errors are only logged in development mode to avoid noise in production logs.
  • Featured items are managed through the admin panel endpoints (see Admin Endpoints).
  • The featuredUntil field supports both permanent featuring (null) and time-limited featuring.