Skip to main content
GET
/
api
/
post
/
{id}
Get Post
curl --request GET \
  --url https://api.example.com/api/post/{id}
{
  "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": {},
    "user": {}
  },
  "message": "<string>"
}

Overview

This endpoint retrieves a specific blog post by its ID. The response includes both the post’s category and user (author) information through eager loading.
This endpoint does not require authentication. It is publicly accessible.

Endpoint

GET /api/post/{id}

Authentication

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

Path Parameters

id
number
required
The unique identifier of the post to retrieve

Request

No additional parameters required.

Response

Success Response (200)

code
number
required
HTTP status code (200 for success)
status
string
required
Status message (“success”)
posts
object
required
The post object with its 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
user
object
User relationship object containing author information
{
  "code": 200,
  "status": "success",
  "posts": {
    "id": 1,
    "user_id": 5,
    "category_id": 2,
    "title": "Introduction to Laravel",
    "content": "Laravel is a powerful PHP framework for building web applications. It provides elegant syntax and many features out of the box...",
    "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"
    },
    "user": {
      "id": 5,
      "name": "John Doe",
      "surname": "Smith",
      "email": "[email protected]",
      "role": "ROLE_USER",
      "created_at": "2026-01-01T09:00:00.000000Z",
      "updated_at": "2026-01-01T09:00:00.000000Z"
    }
  }
}

Error Response (404)

code
number
HTTP status code (404 for not found)
status
string
Status message (“error”)
message
string
Error description
{
  "code": 404,
  "status": "error",
  "message": "La entrada no existe"
}

Implementation Details

The endpoint uses Laravel’s eager loading to retrieve the post with both category and user relationships:
$post = Post::find($id)->load('category')->load('user');
This ensures efficient database queries by loading all related data upfront.
If the post with the specified ID does not exist, the endpoint returns a 404 error with the message “La entrada no existe” (The post does not exist).

Build docs developers (and LLMs) love