curl --request POST \
--url https://api.example.com/api/extractImages \
--header 'Content-Type: application/json' \
--data '
{
"url": "<string>"
}
'{
"success": true,
"images": [
{}
],
"error": "<string>"
}Extracts recipe-related images from a URL
curl --request POST \
--url https://api.example.com/api/extractImages \
--header 'Content-Type: application/json' \
--data '
{
"url": "<string>"
}
'{
"success": true,
"images": [
{}
],
"error": "<string>"
}curl -X POST https://yourdomain.com/api/extractImages \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/recipe/chocolate-chip-cookies"
}'
{
"success": true,
"images": [
"https://example.com/images/chocolate-chip-cookies.jpg",
"https://example.com/images/cookies-on-plate.webp"
]
}
false for error responses.{
"success": false,
"error": "URL is required"
}
<script type="application/ld+json"> tags:
@type: "Recipe" or @type: "ImageObject"image property (supports string, object with url, or array)@graph structuresimg[itemprop="image"] - Schema.org markup.recipe-image img.recipe-photo img.recipe-header imgarticle imgmain img.jpg, .jpeg, .png, .webp, .gif, .svg/image/, /img/, /photo/, /picture//logo, /icon, /avatar, /faviconsrc and data-src attributes| HTTP Status | Error Message | Cause |
|---|---|---|
| 400 | ”URL is required” | Missing or invalid URL parameter |
| 400 | ”Invalid URL format” | Malformed URL string |
| 404-5xx | ”Failed to fetch URL: “ | HTTP error from target server |
| 500 | Error message | Timeout, network error, or unexpected error |
{
"success": false,
"error": "URL is required"
}
{
"success": false,
"error": "Invalid URL format"
}
{
"success": false,
"error": "Failed to fetch URL: 404"
}
fetch API with AbortController for timeout handlingconst extractImages = async (url) => {
const response = await fetch('/api/extractImages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ url }),
});
const data = await response.json();
if (data.success) {
console.log(`Found ${data.images.length} images:`);
data.images.forEach((img, i) => {
console.log(` ${i + 1}. ${img}`);
});
} else {
console.error('Error:', data.error);
}
return data;
};
// Usage
await extractImages('https://example.com/recipe/chocolate-chip-cookies');