Comments API

Nested comments system for blog posts with user associations and timestamps.

Note: Comments are accessed through the posts endpoint: /api/posts/:id/comments

List Comments for a Post

Retrieve all comments for a specific blog post.

GET https://responserift.dev/api/posts/1/comments

Response

[
  {
    "id": 1,
    "postId": 1,
    "userId": 2,
    "body": "Great article! This really helped me understand the concepts.",
    "createdAt": "2024-01-15T14:30:00.000Z"
  },
  {
    "id": 2,
    "postId": 1,
    "userId": 3,
    "body": "I have a question about the implementation...",
    "createdAt": "2024-01-15T15:45:00.000Z"
  }
]

Create a Comment

Add a new comment to a specific blog post.

POST https://responserift.dev/api/posts/1/comments
Content-Type: application/json

{
  "userId": 2,
  "body": "Excellent explanation! Looking forward to more content like this."
}

Required fields: userId, body
Auto-generated: id, postId (from URL), createdAt (current timestamp)

Comment Structure

Fields

  • id - Unique comment identifier
  • postId - ID of the post this comment belongs to
  • userId - ID of the user who wrote the comment
  • body - The comment text content
  • createdAt - ISO timestamp when comment was created

Error Handling

Common error responses and their meanings.

Post Not Found (404)

{
  "error": "Post not found"
}

Validation Errors (400)

{
  "error": "userId is required"
}

Usage Examples

JavaScript/Fetch

// Get comments for a post
const response = await fetch('https://responserift.dev/api/posts/1/comments');
const comments = await response.json();

// Create a new comment
const newComment = await fetch('https://responserift.dev/api/posts/1/comments', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    userId: 2,
    body: 'Great post!'
  })
});

cURL

# Get comments
curl https://responserift.dev/api/posts/1/comments

# Create comment
curl -X POST https://responserift.dev/api/posts/1/comments \
  -H "Content-Type: application/json" \
  -d '{"userId": 2, "body": "Great post!"}'

Warning: All mutations are in-memory only and reset on server restart.

ResponseRift JSON API • Production-Ready, Zero-Config