LeafyLib API Documentation
Integrate LeafyLib's extensive salad recipe database into your applications.
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_KEYWeb 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.
/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.
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
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
]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=avocadohttps://studio--leafylib.us-central1.hosted.app/api/recipes?ingredients=tomato,feta
Response: Same format as /api/all-recipes, but filtered.
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"
}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
]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 */ }
}