Skip to main content
GET
/
api
/
post
/
category
/
{id}
Get Posts by Category
curl --request GET \
  --url https://api.example.com/api/post/category/{id}
{
  "status": "<string>",
  "posts": [
    {
      "id": 123,
      "user_id": 123,
      "category_id": 123,
      "title": "<string>",
      "content": "<string>",
      "image": "<string>",
      "created_at": "<string>",
      "updated_at": "<string>"
    }
  ]
}

Overview

This endpoint retrieves all posts that belong to a specific category. It’s useful for displaying category-specific content or filtering posts by topic.
This endpoint does not require authentication and can be accessed publicly.

Endpoint

GET /api/post/category/{id}

Authentication

No authentication required. This is a public endpoint.

Path Parameters

id
integer
required
The ID of the category to filter posts by

Response

status
string
required
Status message (“success”)
posts
array
required
Array of post objects belonging to the specified category

Request Examples

curl -X GET "https://api.example.com/api/post/category/1"

Response Example

Success (200)
{
  "status": "success",
  "posts": [
    {
      "id": 1,
      "user_id": 3,
      "category_id": 1,
      "title": "Getting Started with Laravel",
      "content": "Laravel is a powerful PHP framework...",
      "image": "1709564730laravel.jpg",
      "created_at": "2024-03-04T10:30:00.000000Z",
      "updated_at": "2024-03-04T10:30:00.000000Z"
    },
    {
      "id": 5,
      "user_id": 2,
      "category_id": 1,
      "title": "Advanced Laravel Techniques",
      "content": "Explore advanced patterns in Laravel development...",
      "image": "1709568920advanced.jpg",
      "created_at": "2024-03-04T12:15:00.000000Z",
      "updated_at": "2024-03-04T12:15:00.000000Z"
    }
  ]
}

Implementation Details

The endpoint filters posts using a simple WHERE clause:
$posts = Post::where('category_id', $id)->get();
If no posts exist for the specified category, the response will contain an empty array in the posts field.

Use Cases

  • Display all posts in a specific category on a category archive page
  • Filter blog content by topic
  • Build category-based navigation
  • Create category-specific RSS feeds

Build docs developers (and LLMs) love