Skip to main content

Endpoints

This page documents two GET endpoints for retrieving articles:

Get Articles by Category

GET /articles/{category}

Get Article by ID

GET /articles/id/{id}
Both endpoints do NOT require authentication. They are publicly accessible.

Get Articles by Category

Retrieves all articles belonging to a specific category.

Path Parameters

category
string
required
The name of the category to filter articles by (e.g., “Tech”, “Anime”)

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/Tech \
  -H "Accept: application/json" \
  -H "Accept-Language: en"

Example Response

{
  "success": true,
  "message": "Article 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",
        "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"
        }
      }
    ]
  }
}

Error Response - Not Found

{
  "success": false,
  "message": "Article not found",
  "errors": null
}

Get Article by ID

Retrieves a specific article by its unique ID.

Path Parameters

id
integer
required
The unique ID of the article to retrieve

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/id/1 \
  -H "Accept: application/json" \
  -H "Accept-Language: en"

Example Response

{
  "success": true,
  "message": "Article retrieved successfully",
  "data": {
    "article": {
      "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"
      }
    }
  }
}

Error Response - Not Found

{
  "success": false,
  "message": "Article not found",
  "errors": null
}

Implementation Notes

  • The category endpoint uses a whereHas query to filter articles by category name
  • Both endpoints eager-load relationships (images, category, subcategory) for optimal performance
  • Laravel’s route model binding is used for the ID endpoint for automatic 404 handling
  • If no articles match the category, a 404 error is returned
Source Code References:
  • Category: ArticleController::show() at /home/daytona/workspace/source/app/Http/Controllers/ArticleController.php:149
  • By ID: ArticleController::showById() at /home/daytona/workspace/source/app/Http/Controllers/ArticleController.php:187

Build docs developers (and LLMs) love