Skip to main content

GET /api/favorites/[username]

Retrieve a user’s public favorites collection by their username. This endpoint enables the shared favorites feature.
This endpoint is public and does not require authentication. Users can share their favorites collections with anyone via their username.

Request

Path parameters

username
string
required
The username of the user whose favorites you want to view

Example request

cURL
curl https://wallwidgy.vercel.app/api/favorites/johndoe
JavaScript
fetch('https://wallwidgy.vercel.app/api/favorites/johndoe')
  .then(response => response.json())
  .then(data => {
    console.log(`${data.displayName} has ${data.favoritesCount} favorites`);
    console.log(data.favorites);
  });
Python
import requests

response = requests.get('https://wallwidgy.vercel.app/api/favorites/johndoe')
data = response.json()

print(f"{data['displayName']} has {data['favoritesCount']} favorites")
print(data['favorites'])

Response

Success response (200)

username
string
The user’s username
displayName
string
The user’s display name (firstName or username if no firstName)
imageUrl
string
URL to the user’s profile image
favorites
string[]
Array of wallpaper IDs in the user’s favorites
favoritesCount
number
Total number of favorites
{
  "username": "johndoe",
  "displayName": "John",
  "imageUrl": "https://img.clerk.com/...",
  "favorites": [
    "wallpaper-abc123",
    "wallpaper-def456",
    "wallpaper-ghi789"
  ],
  "favoritesCount": 3
}

Error responses

{
  "error": "Username is required"
}
Returned when no username is provided in the URL.
{
  "error": "User not found"
}
Returned when no user exists with the specified username.
{
  "error": "Failed to fetch favorites"
}
Returned when there’s an error communicating with Clerk.

Usage example

Build a shared favorites viewer:
async function displayUserFavorites(username) {
  try {
    const response = await fetch(
      `https://wallwidgy.vercel.app/api/favorites/${encodeURIComponent(username)}`
    );
    
    if (response.status === 404) {
      console.error('User not found');
      return;
    }
    
    if (!response.ok) {
      throw new Error('Failed to fetch favorites');
    }
    
    const data = await response.json();
    
    console.log(`Viewing ${data.displayName}'s collection`);
    console.log(`Total favorites: ${data.favoritesCount}`);
    
    // Fetch wallpaper details for each favorite
    const wallpapers = await Promise.all(
      data.favorites.map(id => 
        fetch(`/api/wallpapers/${id}`).then(r => r.json())
      )
    );
    
    // Display wallpapers...
  } catch (error) {
    console.error('Error:', error);
  }
}

displayUserFavorites('johndoe');

Share URL format

Users can share their favorites using this URL pattern:
https://wallwidgy.vercel.app/share/[username]
Example: https://wallwidgy.vercel.app/share/johndoe The share page uses this endpoint to display the user’s favorites collection.

Privacy

Favorites are stored in Clerk’s publicMetadata, making them publicly accessible. Users should be aware that:
  • Anyone can view their favorites if they know the username
  • Favorites are visible on the share page
  • There is no option to make favorites private
Use this endpoint to build features like:
  • Shared favorites galleries
  • User collections
  • Wallpaper recommendations based on similar users
  • Social features around wallpaper discovery

See also

Build docs developers (and LLMs) love