Skip to main content

Endpoint

GET /articles
This endpoint does NOT require authentication. It’s publicly accessible.

Description

Retrieves all articles from the database, ordered by ID in descending order (newest first). Each article includes its associated category, subcategory, and images. This endpoint is typically used for:
  • Displaying product catalogs in mobile/web applications
  • Browsing available tech and anime articles
  • Building article listing pages

Headers

Accept-Language
string
default:"en"
Language preference for response messages. Supported values: en, es
Accept
string
default:"application/json"
Response content type

Response

success
boolean
required
Indicates whether the request was successful
message
string
required
Human-readable message describing the result
data
object
required

Example Request

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

Example Response

{
  "success": true,
  "message": "All articles retrieved successfully",
  "data": {
    "articles": [
      {
        "id": 1,
        "category_id": 2,
        "subcategory_id": 5,
        "name": "Gaming Laptop RTX 4070",
        "description": "High-performance gaming laptop with RTX 4070 graphics card, 16GB RAM, and 1TB SSD",
        "price": 1499.99,
        "images": [
          {
            "id": 1,
            "path": "articles/article_image_1_1234567890.jpg",
            "imageable_type": "App\\Models\\Article",
            "imageable_id": 1
          }
        ],
        "category": {
          "id": 2,
          "name": "Tech"
        },
        "subcategory": {
          "id": 5,
          "name": "Laptops"
        }
      },
      {
        "id": 2,
        "category_id": 1,
        "subcategory_id": 3,
        "name": "Demon Slayer Figure",
        "description": "Premium collectible figure of Tanjiro Kamado from Demon Slayer anime",
        "price": 89.99,
        "images": [],
        "category": {
          "id": 1,
          "name": "Anime"
        },
        "subcategory": {
          "id": 3,
          "name": "Figures"
        }
      }
    ]
  }
}

Error Responses

This endpoint typically doesn’t return errors as it will return an empty array if no articles exist. However, server errors may occur:

500 - Internal Server Error

{
  "success": false,
  "message": "An error occurred while retrieving articles",
  "errors": {
    "exception": "Database connection failed"
  }
}

Implementation Notes

  • Articles are ordered by ID in descending order (newest first)
  • All relationships (category, subcategory, images) are eager-loaded for performance
  • No pagination is currently implemented - all articles are returned
  • The endpoint uses the ArticleResource for consistent response formatting
Source Code Reference: ArticleController::index() at /home/daytona/workspace/source/app/Http/Controllers/ArticleController.php:55

Build docs developers (and LLMs) love