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

Overview

This endpoint retrieves all blog posts from the database. Each post includes its associated category information through eager loading.
This endpoint does not require authentication. It is publicly accessible.

Endpoint

GET /api/post

Authentication

No authentication required. This endpoint is excluded from the api.auth middleware.

Request

No parameters required.

Response

code
number
required
HTTP status code (200 for success)
status
string
required
Status message (“success”)
posts
array
required
Array of post objects with their relationships
id
number
Unique identifier for the post
user_id
number
ID of the user who created the post
category_id
number
ID of the post’s category
title
string
Title of the post
content
string
Content/body of the post
image
string
Filename of the post’s image
created_at
string
Timestamp when the post was created
updated_at
string
Timestamp when the post was last updated
category
object
Category relationship object containing category details

Success Response

{
  "code": 200,
  "status": "success",
  "posts": [
    {
      "id": 1,
      "user_id": 5,
      "category_id": 2,
      "title": "Introduction to Laravel",
      "content": "Laravel is a powerful PHP framework...",
      "image": "1678901234image.jpg",
      "created_at": "2026-03-01T10:30:00.000000Z",
      "updated_at": "2026-03-01T10:30:00.000000Z",
      "category": {
        "id": 2,
        "name": "Technology",
        "created_at": "2026-01-15T08:00:00.000000Z",
        "updated_at": "2026-01-15T08:00:00.000000Z"
      }
    },
    {
      "id": 2,
      "user_id": 3,
      "category_id": 1,
      "title": "Getting Started with APIs",
      "content": "APIs are essential for modern web development...",
      "image": "1678901567api.png",
      "created_at": "2026-03-02T14:20:00.000000Z",
      "updated_at": "2026-03-02T14:20:00.000000Z",
      "category": {
        "id": 1,
        "name": "Web Development",
        "created_at": "2026-01-10T12:00:00.000000Z",
        "updated_at": "2026-01-10T12:00:00.000000Z"
      }
    }
  ]
}

Implementation Details

The endpoint uses Laravel’s eager loading to retrieve posts with their category relationships:
$posts = Post::all()->load('category');
This prevents N+1 query problems by loading all category data in a single additional query.

Build docs developers (and LLMs) love