Skip to main content

GET /api/recetas

Returns a paginated list of public recipes. Only recipes where oculta is false are returned, sorted by creation date descending. Each recipe includes the author’s profile data.
No authentication is required to list recipes.

Query parameters

busqueda
string
Filter recipes by title. Performs a case-insensitive partial match.
page
integer
default:"1"
Page number to retrieve.
limit
integer
default:"16"
Number of results per page.

Response fields

data
array
required
Array of recipe objects for the requested page.
totalPages
integer
required
Total number of pages for the current query.
currentPage
integer
required
The page number returned in this response.

Example request

curl -X GET "https://example.com/api/recetas?busqueda=pasta&page=1&limit=16"

Example response

{
  "data": [
    {
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "titulo": "Pasta al pesto",
      "descripcion": "Una receta clásica italiana con albahaca fresca.",
      "tiempo": "20 minutos",
      "dificultad": "Fácil",
      "ingredientes": "[\"pasta\", \"albahaca\", \"ajo\", \"aceite de oliva\"]",
      "pasos": "[\"Cocer la pasta.\", \"Preparar el pesto.\", \"Mezclar y servir.\"]",
      "imagen_url": "https://example.com/images/pasta.jpg",
      "oculta": false,
      "fecha_creacion": "2024-03-15T10:30:00.000Z",
      "autor_id": "f1e2d3c4-b5a6-7890-abcd-ef0987654321",
      "perfiles": {
        "nombre": "María García",
        "avatar_url": "https://example.com/avatars/maria.jpg"
      }
    }
  ],
  "totalPages": 4,
  "currentPage": 1
}

POST /api/recetas

Creates a new recipe. The recipe is automatically associated with the authenticated user and set to visible (oculta: false).
Authentication is required. Requests without a valid session return 401 Unauthorized.

Request body

titulo
string
required
Title of the recipe. Maximum 60 characters. Leading and trailing whitespace is trimmed.
descripcion
string
required
Short description of the recipe. Maximum 300 characters. Leading and trailing whitespace is trimmed.
tiempo
string
required
Preparation and cooking time (e.g., "30 minutos"). Leading and trailing whitespace is trimmed.
dificultad
string
Difficulty level (e.g., "Fácil", "Medio", "Difícil").
ingredientes
string[]
required
Array of ingredient strings. Empty strings and whitespace-only entries are ignored. At least one valid entry is required.
pasos
string[]
required
Array of step strings describing the preparation process. Empty strings and whitespace-only entries are ignored. At least one valid entry is required.
imagen_url
string
URL of the recipe image. Stored as null if not provided.

Validation rules

  • titulo, descripcion, and tiempo are required and must not be blank after trimming.
  • titulo must not exceed 60 characters.
  • descripcion must not exceed 300 characters.
  • ingredientes and pasos must each contain at least one non-empty string.

Response

Returns 201 Created on success.
{
  "message": "Receta creada con éxito"
}

Error responses

StatusCondition
400Missing required fields, validation failure, or database error
401No authenticated session
500Unexpected server error

Example request

curl -X POST "https://example.com/api/recetas" \
  -H "Content-Type: application/json" \
  -H "Cookie: <session-cookie>" \
  -d '{
    "titulo": "Pasta al pesto",
    "descripcion": "Una receta clásica italiana con albahaca fresca.",
    "tiempo": "20 minutos",
    "dificultad": "Fácil",
    "ingredientes": ["pasta", "albahaca", "ajo", "aceite de oliva"],
    "pasos": ["Cocer la pasta.", "Preparar el pesto.", "Mezclar y servir."],
    "imagen_url": "https://example.com/images/pasta.jpg"
  }'

Example response

{
  "message": "Receta creada con éxito"
}

Build docs developers (and LLMs) love