Skip to main content
POST
/
api
/
urlValidator
URL Validator
curl --request POST \
  --url https://api.example.com/api/urlValidator \
  --header 'Content-Type: application/json' \
  --data '
{
  "url": "<string>"
}
'
{
  "success": true,
  "isRecipe": true,
  "error": {
    "code": "<string>",
    "message": "<string>"
  }
}

Overview

The URL Validator endpoint validates a given URL and determines whether it contains recipe content. It performs URL format validation, fetches the page content, and analyzes it for recipe-specific indicators such as ingredients, instructions, and Recipe schema markup.

Request

url
string
required
The URL to validate. Must be a valid, well-formed URL string.

Example Request

curl -X POST https://yourdomain.com/api/urlValidator \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/recipe/chocolate-chip-cookies"
  }'

Response

Success Response

success
boolean
Indicates whether the operation was successful.
isRecipe
boolean
Indicates whether the URL contains recipe content.
{
  "success": true,
  "isRecipe": true
}

Error Response

success
boolean
Always false for error responses.
error
object
Error details object.
code
string
Error code identifier (e.g., ERR_INVALID_URL, ERR_NO_RECIPE_FOUND, ERR_TIMEOUT).
message
string
Human-readable error message.

Recipe Detection Logic

The endpoint considers a page to contain recipe content if:
  1. Schema-based detection: The page contains Recipe schema markup (@type: "Recipe" in JSON-LD)
  2. Content-based detection: The page contains both:
    • Text mentioning “ingredient” or “ingredients”
    • Text mentioning “instruction”, “step”, or “directions”

Error Handling

The endpoint handles various error scenarios:
Error CodeStatusDescription
ERR_INVALID_URL200URL parameter is missing, not a string, or invalid format
ERR_NO_RECIPE_FOUND200Page not found (404), empty content, or no recipe detected
ERR_TIMEOUT200Request timed out after 10 seconds
ERR_FETCH_FAILED200Network error or server error (5xx)
ERR_UNKNOWN200Unexpected error occurred

Error Response Examples

Invalid URL format:
{
  "success": false,
  "error": {
    "code": "ERR_INVALID_URL",
    "message": "Please enter a valid URL"
  }
}
No recipe found:
{
  "success": false,
  "error": {
    "code": "ERR_NO_RECIPE_FOUND",
    "message": "No recipe found on this page"
  }
}
Timeout:
{
  "success": false,
  "error": {
    "code": "ERR_TIMEOUT",
    "message": "Request timed out"
  }
}

Configuration

  • Timeout: 10 seconds
  • User-Agent: Simulates Chrome browser
  • Accepted languages: English (en-US, en)
  • Domain restrictions: None (supports any recipe website)

Implementation Notes

  • The endpoint removes domain restrictions and supports any recipe website
  • Uses cheerio for HTML parsing and content analysis
  • Fetches pages with browser-like headers to avoid bot detection
  • Returns consistent error structure using the formatError utility

Build docs developers (and LLMs) love