Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/pvnm4/Social-Media-Backend/llms.txt

Use this file to discover all available pages before exploring further.

The PUT /posts/{id} endpoint fully replaces the content of an existing post. Because this is a PUT (not PATCH), all fields must be provided — omitting a field resets it to its default value. Only the user who originally created the post can update it; attempting to update a post owned by another user returns a 403 Forbidden error.

Endpoint

PUT /posts/{id}
Authentication required — include a Bearer token in the Authorization header.

Path Parameters

id
integer
required
The unique numeric identifier of the post to update.

Request Body

title
string
required
The new title for the post. Replaces the existing title entirely.
content
string
required
The new body/content for the post. Replaces the existing content entirely.
published
boolean
default:true
The new published status. Replaces the existing value. Defaults to true if omitted.

Response

HTTP 200 OK — Returns the updated Post object.
id
integer
The unique numeric ID of the updated post.
title
string
The updated title of the post.
content
string
The updated body/content of the post.
published
boolean
The updated published status of the post.
created_at
string (datetime)
ISO 8601 timestamp of when the post was originally created. This value is not changed by an update.
owner
object
Details of the user who owns the post.

Error Responses

Status CodeDescription
401 UnauthorizedNo token was provided or the token is invalid/expired.
403 ForbiddenThe authenticated user is not the owner of this post. Message: "Not authorized to perform requested action".
404 Not FoundNo post with the specified id exists. Message: "Post with the id:{id} does not exists".
422 Unprocessable EntityThe request body is missing required fields or contains invalid values.

Examples

# Update post with ID 42 (all fields must be supplied)
curl -X PUT http://localhost:8000/posts/42 \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Updated Title",
    "content": "This content has been revised.",
    "published": true
  }'

# Unpublish a post
curl -X PUT http://localhost:8000/posts/42 \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Updated Title",
    "content": "This content has been revised.",
    "published": false
  }'

Successful Response Example

{
  "id": 42,
  "title": "Updated Title",
  "content": "This content has been revised.",
  "published": true,
  "created_at": "2024-01-20T12:00:00.000000Z",
  "owner": {
    "id": 3,
    "email": "alice@example.com",
    "created_at": "2024-01-01T08:00:00.000000Z"
  }
}

403 Forbidden Response Example

{
  "detail": "Not authorized to perform requested action"
}

404 Not Found Response Example

{
  "detail": "Post with the id:42 does not exists"
}
This endpoint performs a full replacement. All fields (title, content, published) must be included in every request. Omitting published will reset it to its default value of true.

Build docs developers (and LLMs) love