Nikode API

Comments API

Comment system for characters with moderation features

Overview

The Comments API allows you to:

  • Retrieve comments with pagination and filtering
  • Get individual comment details
  • Create new comments (Public access)
  • Update comment content (Comment author or Moderator+)
  • Delete comments (Comment author, Moderator, or Admin)
  • Moderate comments (Moderator+)

Endpoints

GET /api/comments

Retrieve a list of comments with optional filtering, sorting, and pagination.

Permissions: Public access

Query Parameters:

  • page (number, default: 1): Page number for pagination
  • limit (number, default: 10, max: 100): Number of items per page
  • characterId (string, optional): Filter by character ID
  • userId (string, optional): Filter by user ID
  • status (string, optional): Filter by status (pending, approved, rejected)
  • sortBy (string, default: "createdAt"): Sort field (createdAt, updatedAt, rating)
  • sortOrder (string, default: "desc"): Sort order (asc, desc)

Example Request:

curl "https://api.nikode.ir/api/comments?page=1&limit=10&characterId=char_1&status=approved"

Example Response:

{
  "success": true,
  "message": "Comments retrieved successfully",
  "data": [
    {
      "id": "comment_1",
      "characterId": "char_1",
      "userId": "user_1",
      "content": "This character is amazing! Love their abilities.",
      "rating": 5,
      "status": "approved",
      "createdAt": "2024-01-01T00:00:00.000Z",
      "updatedAt": "2024-01-01T00:00:00.000Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 10,
    "total": 25,
    "totalPages": 3,
    "hasNext": true,
    "hasPrev": false
  }
}
GETTest GET /api/comments

Retrieve comments with filtering and pagination

POST /api/comments

Create a new comment.

Permissions: Public access

Request Body:

{
  "characterId": "string (required)",
  "content": "string (required, max 1000 characters)",
  "rating": "number (optional, 1-5)"
}

Example Request:

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "characterId": "char_1",
    "content": "This character is absolutely incredible! Their power level and abilities are unmatched.",
    "rating": 5
  }' \
  "https://api.nikode.ir/api/comments"

Example Response:

{
  "success": true,
  "message": "Comment created successfully",
  "data": {
    "id": "comment_new_id",
    "characterId": "char_1",
    "userId": "user_1",
    "content": "This character is absolutely incredible! Their power level and abilities are unmatched.",
    "rating": 5,
    "status": "pending",
    "createdAt": "2024-01-01T00:00:00.000Z",
    "updatedAt": "2024-01-01T00:00:00.000Z"
  }
}
POSTTest POST /api/comments

Create a new comment

GET /api/comments/[id]

Retrieve a specific comment by ID.

Permissions: Public access

Path Parameters:

  • id (string, required): Comment ID

Example Request:

curl "https://api.nikode.ir/api/comments/comment_1"

Example Response:

{
  "success": true,
  "message": "Comment retrieved successfully",
  "data": {
    "id": "comment_1",
    "characterId": "char_1",
    "userId": "user_1",
    "content": "This character is amazing! Love their abilities.",
    "rating": 5,
    "status": "approved",
    "createdAt": "2024-01-01T00:00:00.000Z",
    "updatedAt": "2024-01-01T00:00:00.000Z"
  }
}
GETTest GET /api/comments/[id]

Retrieve a specific comment by ID

PUT /api/comments/[id]

Update a comment's content.

Permissions: Comment author or Moderator+

Path Parameters:

  • id (string, required): Comment ID

Request Body:

{
  "content": "string (required, max 1000 characters)",
  "rating": "number (optional, 1-5)"
}

Example Request:

curl -X PUT \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Updated comment content with more details about the character.",
    "rating": 4
  }' \
  "https://api.nikode.ir/api/comments/comment_1"

Example Response:

{
  "success": true,
  "message": "Comment updated successfully",
  "data": {
    "id": "comment_1",
    "characterId": "char_1",
    "userId": "user_1",
    "content": "Updated comment content with more details about the character.",
    "rating": 4,
    "status": "approved",
    "createdAt": "2024-01-01T00:00:00.000Z",
    "updatedAt": "2024-01-01T12:00:00.000Z"
  }
}
PUTTest PUT /api/comments/[id]

Update a comment (requires comment author or moderator+ role)

DELETE /api/comments/[id]

Delete a comment.

Permissions: Comment author, Moderator, or Admin

Path Parameters:

  • id (string, required): Comment ID

Example Request:

curl -X DELETE "https://api.nikode.ir/api/comments/comment_1"

Example Response:

{
  "success": true,
  "message": "Comment deleted successfully",
  "data": {
    "id": "comment_1",
    "characterId": "char_1",
    "userId": "user_1",
    "content": "This character is amazing! Love their abilities.",
    "rating": 5,
    "status": "approved",
    "createdAt": "2024-01-01T00:00:00.000Z",
    "updatedAt": "2024-01-01T00:00:00.000Z"
  }
}
DELETETest DELETE /api/comments/[id]

Delete a comment (requires comment author, moderator, or admin role)

PATCH /api/comments/[id]/moderate

Moderate a comment (approve/reject).

Permissions: Moderator or Admin

Path Parameters:

  • id (string, required): Comment ID

Request Body:

{
  "status": "string (required, 'approved' or 'rejected')",
  "reason": "string (optional, reason for rejection)"
}

Example Request:

curl -X PATCH \
  -H "Content-Type: application/json" \
  -d '{
    "status": "approved"
  }' \
  "https://api.nikode.ir/api/comments/comment_1/moderate"

Example Response:

{
  "success": true,
  "message": "Comment moderated successfully",
  "data": {
    "id": "comment_1",
    "characterId": "char_1",
    "userId": "user_1",
    "content": "This character is amazing! Love their abilities.",
    "rating": 5,
    "status": "approved",
    "createdAt": "2024-01-01T00:00:00.000Z",
    "updatedAt": "2024-01-01T12:00:00.000Z"
  }
}
PATCHTest PATCH /api/comments/[id]/moderate

Moderate a comment (requires moderator or admin role)

Data Models

Comment Object

interface Comment {
  id: string;
  characterId: string;
  userId: string;
  content: string;
  rating?: number; // 1-5
  status: "pending" | "approved" | "rejected";
  createdAt: string; // ISO 8601
  updatedAt: string; // ISO 8601
}

Create Comment Request

interface CreateComment {
  characterId: string;
  content: string; // max 1000 characters
  rating?: number; // 1-5
}

Update Comment Request

interface UpdateComment {
  content: string; // max 1000 characters
  rating?: number; // 1-5
}

Moderate Comment Request

interface ModerateComment {
  status: "approved" | "rejected";
  reason?: string; // reason for rejection
}

Comment Status Flow

  1. Pending: New comments start in pending status
  2. Approved: Moderators can approve comments to make them visible
  3. Rejected: Moderators can reject comments with a reason

Error Codes

CodeStatusDescription
FORBIDDEN403Insufficient permissions for operation
NOT_FOUND404Comment not found
VALIDATION_ERROR400Invalid request data
CONFLICT409Comment already exists
INTERNAL_ERROR500Server error

Rate Limits

  • User: 100 requests per hour
  • Moderator: 500 requests per hour
  • Admin: 1000 requests per hour

Examples

JavaScript/Node.js

// Get all comments
const response = await fetch("/api/comments");
const comments = await response.json();

// Create a comment
const newComment = await fetch("/api/comments", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    characterId: "char_1",
    content: "This character is absolutely incredible!",
    rating: 5,
  }),
});

// Moderate a comment
const moderateComment = await fetch("/api/comments/comment_1/moderate", {
  method: "PATCH",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    status: "approved",
  }),
});

Python

import requests

# Get all comments
response = requests.get('https://api.nikode.ir/api/comments')
comments = response.json()

# Create a comment
new_comment = requests.post(
    'https://api.nikode.ir/api/comments',
    headers={
        'Content-Type': 'application/json'
    },
    json={
        'characterId': 'char_1',
        'content': 'This character is absolutely incredible!',
        'rating': 5
    }
)

# Moderate a comment
moderate_comment = requests.patch(
    'https://api.nikode.ir/api/comments/comment_1/moderate',
    headers={
        'Content-Type': 'application/json'
    },
    json={
        'status': 'approved'
    }
)

cURL

# Get all comments
curl "https://api.nikode.ir/api/comments"

# Get comments with filtering
curl "https://api.nikode.ir/api/comments?characterId=char_1&status=approved&sortBy=createdAt&sortOrder=desc"

# Create a comment
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "characterId": "char_1",
    "content": "This character is absolutely incredible!",
    "rating": 5
  }' \
  "https://api.nikode.ir/api/comments"

# Moderate a comment
curl -X PATCH \
  -H "Content-Type: application/json" \
  -d '{
    "status": "approved"
  }' \
  "https://api.nikode.ir/api/comments/comment_1/moderate"