Skip to main content
GET
/
api
/
post
/
user
/
{id}
Get Posts by User
curl --request GET \
  --url https://api.example.com/api/post/user/{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 authored by a specific user. It’s useful for displaying user profiles, author archives, or filtering content by contributor.
This endpoint does not require authentication and can be accessed publicly.

Endpoint

GET /api/post/user/{id}

Authentication

No authentication required. This is a public endpoint.

Path Parameters

id
integer
required
The ID of the user whose posts you want to retrieve

Response

status
string
required
Status message (“success”)
posts
array
required
Array of post objects created by the specified user

Request Examples

curl -X GET "https://api.example.com/api/post/user/2"

Response Example

Success (200)
{
  "status": "success",
  "posts": [
    {
      "id": 3,
      "user_id": 2,
      "category_id": 1,
      "title": "My First Blog Post",
      "content": "This is my inaugural post on the blog...",
      "image": "1709564730first.jpg",
      "created_at": "2024-03-01T09:00:00.000000Z",
      "updated_at": "2024-03-01T09:00:00.000000Z"
    },
    {
      "id": 7,
      "user_id": 2,
      "category_id": 3,
      "title": "Travel Photography Tips",
      "content": "Here are my top tips for capturing stunning travel photos...",
      "image": "1709568920travel.jpg",
      "created_at": "2024-03-03T14:30:00.000000Z",
      "updated_at": "2024-03-03T14:30:00.000000Z"
    },
    {
      "id": 9,
      "user_id": 2,
      "category_id": 2,
      "title": "Cooking Italian Cuisine",
      "content": "Authentic Italian recipes from my kitchen...",
      "image": "1709571200cooking.jpg",
      "created_at": "2024-03-04T08:00:00.000000Z",
      "updated_at": "2024-03-04T08:00:00.000000Z"
    }
  ]
}

Implementation Details

The endpoint filters posts using a simple WHERE clause:
$posts = Post::where('user_id', $id)->get();
If the specified user has not created any posts, the response will contain an empty array in the posts field.

Use Cases

  • Display all posts on an author profile page
  • Show contributor portfolios
  • Build author-based archives
  • Track content creation by user
  • Generate per-author RSS feeds

Build docs developers (and LLMs) love