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 POST /posts/ endpoint creates a new post and automatically associates it with the currently authenticated user. The owner_id field is derived directly from the JWT token — it cannot be set or overridden in the request body. A valid Bearer token must be included with every request.

Endpoint

POST /posts/
Authentication required — include a Bearer token in the Authorization header.

Request Body

title
string
required
The title of the post. Must be a non-empty string.
content
string
required
The body or main content of the post. Must be a non-empty string.
published
boolean
default:true
Whether the post should be marked as published. Defaults to true if not provided.

Response

HTTP 201 Created — Returns the newly created Post object.
id
integer
The auto-generated unique numeric ID assigned to the new post.
title
string
The title of the post as provided in the request.
content
string
The body/content of the post as provided in the request.
published
boolean
Whether the post is published.
created_at
string (datetime)
ISO 8601 timestamp of when the post was created, set automatically by the server.
owner
object
Details of the authenticated user who created the post.

Error Responses

Status CodeDescription
401 UnauthorizedNo token was provided or the token is invalid/expired.
422 Unprocessable EntityThe request body is missing required fields or contains invalid values.

Examples

# Create a published post
curl -X POST http://localhost:8000/posts/ \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "My First Post",
    "content": "This is the content of my first post.",
    "published": true
  }'

# Create a draft post (published: false)
curl -X POST http://localhost:8000/posts/ \
  -H "Authorization: Bearer TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Draft Post",
    "content": "Work in progress.",
    "published": false
  }'

Successful Response Example

{
  "id": 42,
  "title": "My First Post",
  "content": "This is the content of my first post.",
  "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"
  }
}

Build docs developers (and LLMs) love