LeafyLib API Documentation

Integrate LeafyLib's extensive salad recipe database into your applications.

API Key Authentication
All API requests must be authenticated using an API key.

To use the LeafyLib API, you need to include your API key in the Authorization header of your requests. The key should be prefixed with Bearer .

Example Header:

Authorization: Bearer YOUR_API_KEY

Web Application Key

The primary API key for client-side calls from the LeafyLib web application is set in your .env file as NEXT_PUBLIC_API_SECRET_KEY.

Important Note: The `NEXT_PUBLIC_` prefix means this key is embedded in your client-side JavaScript bundle and is visible in the browser. This is suitable for prototyping and development where the client directly calls these APIs. For the "Suggest with AI" form on this website (which calls /api/recipes/suggest), the client-side JavaScript uses this public key to authenticate.

Mobile Application Key

For mobile applications (e.g., Flutter, React Native, Swift, Kotlin), a separate API key can be used. This key is defined in your .env file as MOBILE_APP_API_KEY.

MOBILE_APP_API_KEY="REPLACE_WITH_YOUR_SECURE_MOBILE_API_KEY"

It is recommended to use this distinct key for mobile clients. Ensure you replace the placeholder with a strong, unique key. The mobile application should send this key in the `Authorization: Bearer YOUR_MOBILE_APP_API_KEY` header.

Security Best Practice: For production mobile applications, consider implementing a backend-for-frontend (BFF). The mobile app would authenticate with your BFF, and the BFF would securely manage and use the API key to communicate with the LeafyLib API. This avoids embedding the API key directly in the mobile app binary.

If an invalid key is provided, or if the relevant key is not set on the server, the API will return a 401 Unauthorized or 500 Internal Server Error respectively.

Available Endpoints

Base URL for all endpoints: https://studio--leafylib.us-central1.hosted.app

GET /api/all-recipes
Retrieves a list of all available salad recipes.
Method:
GET

URL: https://studio--leafylib.us-central1.hosted.app/api/all-recipes

Authentication: Required (Bearer Token with Web or Mobile API Key)

Response:

[
  {
    "id": "1",
    "title": "Classic Greek Salad",
    "description": "A refreshing and tangy salad...",
    "imageUrl": "/images/greek.jpeg",
    "dataAiHint": "greek salad feta cheese olives",
    "ingredients": [
      { "item": "Cucumber", "quantity": "1 large, chopped" },
      // ... more ingredients
    ],
    "dressing": [
      { "item": "Olive Oil", "quantity": "1/4 cup" },
      // ... more dressing ingredients
    ],
    "preparationSteps": ["Step 1...", "Step 2..."],
    "isVegan": false,
    "prepTime": "20 minutes",
    "servings": 4,
    "notes": "For a vegan version..."
  },
  // ... more recipes
]
GET /api/recipes
Searches recipes by keyword or by ingredients.
Method:
GET

Authentication: Required (Bearer Token with Web or Mobile API Key)

Query Parameters:

  • q (string, optional): A keyword to search in title, description, and ingredients.
  • ingredients (string, optional): A comma-separated list of ingredients. Recipes containing at least one of these will be returned.

Example URLs:

  • https://studio--leafylib.us-central1.hosted.app/api/recipes?q=avocado
  • https://studio--leafylib.us-central1.hosted.app/api/recipes?ingredients=tomato,feta

Response: Same format as /api/all-recipes, but filtered.

GET /api/recipes/[id]
Retrieves a specific recipe by its unique ID.
Method:
GET

Authentication: Required (Bearer Token with Web or Mobile API Key)

URL Structure: https://studio--leafylib.us-central1.hosted.app/api/recipes/<recipe_id>

Example URL: https://studio--leafylib.us-central1.hosted.app/api/recipes/1

Response: A single recipe object (same structure as in the array from /api/all-recipes).

Error Response (404): If recipe not found.

{
  "message": "Recipe not found"
}
GET /api/ingredients
Retrieves a unique, sorted list of all ingredients, each with its name and image path.
Method:
GET

URL: https://studio--leafylib.us-central1.hosted.app/api/ingredients

Authentication: Required (Bearer Token with Web or Mobile API Key)

Response:

[
  {
    "name": "Avocado",
    "imagePath": "/images/Avocado.jpeg"
  },
  {
    "name": "Baby Spinach",
    "imagePath": "/images/Baby-spinach.jpeg"
  },
  // ... more ingredients
]
POST /api/recipes/suggest
Suggests salad recipes based on a list of provided ingredients using AI.
Method:
POST

URL: https://studio--leafylib.us-central1.hosted.app/api/recipes/suggest

Authentication: Required (Bearer Token with Web or Mobile API Key)

Request Body (JSON):

{
  "ingredients": "lettuce, tomato, cucumber, chicken"
}

Response (JSON):

{
  "recipes": "1. Chicken Caesar Salad: Combine lettuce, chopped chicken, croutons, and Caesar dressing.\n\n2. Tomato Cucumber Chicken Salad: Mix diced tomatoes, cucumbers, grilled chicken, and a light vinaigrette."
  // (Actual AI response format might vary slightly but will contain suggested recipes as a string)
}

Error Response (400): If input is invalid.

{
  "message": "Invalid input",
  "errors": { /* Zod error details */ }
}