Skip to main content

Overview

The Resources API allows you to manage learning materials that support course topics. Resources can be videos, PDF documents, or presentations, each with metadata like duration, descriptions, and URLs. Resources are linked to specific topics and optionally to the instructor who created them.

Endpoints

List All Resources

Retrieve a list of all learning resources in the system.
GET /api/resources

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Recursos listados con éxito”
data
array
Array of resource objects

Example Request

curl -X GET https://api.example.com/api/resources \
  -H "Accept: application/json"

Example Response

{
  "success": true,
  "message": "Recursos listados con éxito",
  "data": [
    {
      "id": 1,
      "topics_id": 5,
      "docente_id": 12,
      "tipo": "video",
      "titulo": "Introducción a las Variables en PHP",
      "descripcion": "Video explicativo sobre el uso de variables y tipos de datos en PHP",
      "url": "https://storage.example.com/videos/php-variables.mp4",
      "duracion_min": 25,
      "activo": 1
    },
    {
      "id": 2,
      "topics_id": 5,
      "docente_id": 12,
      "tipo": "pdf",
      "titulo": "Guía de Sintaxis PHP",
      "descripcion": "Documento PDF con ejemplos de sintaxis básica de PHP",
      "url": "https://storage.example.com/docs/php-syntax-guide.pdf",
      "duracion_min": null,
      "activo": 1
    }
  ]
}

Create Resource

Create a new learning resource.
POST /api/resources

Request Body

topics_id
integer
required
ID of the topic this resource belongs to
docente_id
integer
ID of the instructor creating this resource (optional)
tipo
enum
required
Type of resource. Must be one of: video, pdf, presentacion
titulo
string
required
Title of the resource (maximum 200 characters)
descripcion
text
Detailed description of the resource (optional)
url
string
URL where the resource is hosted (maximum 500 characters, optional)
duracion_min
integer
Duration in minutes (optional, typically used for videos)
activo
tinyint
default:"1"
Active status (0 = inactive, 1 = active)

Response

success
boolean
Indicates if the resource was created successfully
message
string
Response message: “Recurso creado con éxito”
data
object
The created resource object with all fields

Example Request

curl -X POST https://api.example.com/api/resources \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "topics_id": 5,
    "docente_id": 12,
    "tipo": "video",
    "titulo": "Arrays en PHP",
    "descripcion": "Tutorial completo sobre arrays indexados y asociativos",
    "url": "https://storage.example.com/videos/php-arrays.mp4",
    "duracion_min": 30,
    "activo": 1
  }'

Example Response

{
  "success": true,
  "message": "Recurso creado con éxito",
  "data": {
    "id": 15,
    "topics_id": 5,
    "docente_id": 12,
    "tipo": "video",
    "titulo": "Arrays en PHP",
    "descripcion": "Tutorial completo sobre arrays indexados y asociativos",
    "url": "https://storage.example.com/videos/php-arrays.mp4",
    "duracion_min": 30,
    "activo": 1
  }
}

Get Resource

Retrieve a specific resource by ID.
GET /api/resources/{id}

Path Parameters

id
integer
required
The unique identifier of the resource

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Recurso obtenido con éxito”
data
object
The resource object with all fields

Example Request

curl -X GET https://api.example.com/api/resources/15 \
  -H "Accept: application/json"

Example Response

{
  "success": true,
  "message": "Recurso obtenido con éxito",
  "data": {
    "id": 15,
    "topics_id": 5,
    "docente_id": 12,
    "tipo": "video",
    "titulo": "Arrays en PHP",
    "descripcion": "Tutorial completo sobre arrays indexados y asociativos",
    "url": "https://storage.example.com/videos/php-arrays.mp4",
    "duracion_min": 30,
    "activo": 1
  }
}

Update Resource

Update an existing resource.
PUT /api/resources/{id}

Path Parameters

id
integer
required
The unique identifier of the resource to update

Request Body

topics_id
integer
ID of the topic this resource belongs to
docente_id
integer
ID of the instructor
tipo
enum
Type of resource: video, pdf, or presentacion
titulo
string
Title of the resource (maximum 200 characters)
descripcion
text
Detailed description
url
string
Resource URL (maximum 500 characters)
duracion_min
integer
Duration in minutes
activo
tinyint
Active status (0 or 1)

Response

success
boolean
Indicates if the update was successful
message
string
Response message: “Recurso actualizado con éxito”
data
object
The updated resource object

Example Request

curl -X PUT https://api.example.com/api/resources/15 \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "titulo": "Arrays y Colecciones en PHP",
    "descripcion": "Tutorial ampliado sobre arrays, colecciones y funciones de array",
    "duracion_min": 45
  }'

Example Response

{
  "success": true,
  "message": "Recurso actualizado con éxito",
  "data": {
    "id": 15,
    "topics_id": 5,
    "docente_id": 12,
    "tipo": "video",
    "titulo": "Arrays y Colecciones en PHP",
    "descripcion": "Tutorial ampliado sobre arrays, colecciones y funciones de array",
    "url": "https://storage.example.com/videos/php-arrays.mp4",
    "duracion_min": 45,
    "activo": 1
  }
}

Delete Resource

Delete a resource from the system.
DELETE /api/resources/{id}

Path Parameters

id
integer
required
The unique identifier of the resource to delete

Response

success
boolean
Indicates if the deletion was successful
message
string
Response message: “Recurso eliminado con éxito”
data
null
Returns null after successful deletion

Example Request

curl -X DELETE https://api.example.com/api/resources/15 \
  -H "Accept: application/json"

Example Response

{
  "success": true,
  "message": "Recurso eliminado con éxito",
  "data": null
}

Foreign Key Relationships

Topics Relationship

  • Field: topics_id
  • References: topics.id
  • On Delete: CASCADE (deleting a topic will delete all associated resources)

Instructor Relationship

  • Field: docente_id
  • References: users.id
  • On Delete: SET NULL (deleting a user will set the field to null, preserving the resource)

Notes

  • The tipo field is restricted to three values: video, pdf, or presentacion
  • The duracion_min field is typically used for video resources to indicate playback time
  • Resources are soft-deletable via the activo flag (set to 0) without removing from database
  • All resources must be associated with a valid topic via topics_id
  • The url field can store external links or internal storage paths

Build docs developers (and LLMs) love