Complete blog API with posts, comments, authors, and categories. Demonstrates nested resources, relationships, and complex query patterns. Production-ready configuration included.
A complete blog API demonstrating advanced concepts like nested resources, relationships between entities, comments threading, and content management.
📋 What You'll Get
✅ Posts with authors and categories
✅ Nested comments with threading
✅ User management and authentication
✅ Tags and categorization
✅ Search and filtering
✅ Publish/draft workflow
🏗️ Architecture Diagram
graph TD A[Blog API] --> B[Posts] A --> C[Users/Authors] A --> D[Comments] A --> E[Categories] B -->|belongs to| C B -->|has many| D B -->|has many| F[Tags] D -->|belongs to| C D -->|belongs to| B D -->|can reply to| D style A fill:#f9f,stroke:#333,stroke-width:2px style B fill:#bbf,stroke:#333,stroke-width:2px style C fill:#bfb,stroke:#333,stroke-width:2px style D fill:#fbb,stroke:#333,stroke-width:2px
🎯 API Overview
Core Endpoints
Resource
Method
Path
Description
Posts
GET
/posts
List all posts
GET
/posts/:id
Get specific post
POST
/posts
Create post
PUT
/posts/:id
Update post
DELETE
/posts/:id
Delete post
Comments
GET
/posts/:postId/comments
List post comments
POST
/posts/:postId/comments
Add comment
GET
/comments/:id
Get comment
DELETE
/comments/:id
Delete comment
Authors
GET
/authors
List authors
GET
/authors/:id
Get author
GET
/authors/:id/posts
Author's posts
Categories
GET
/categories
List categories
GET
/categories/:slug/posts
Category posts
📁 Configuration File
Create blog-api.yml:
🚀 Usage Examples
Start Server
Posts Management
Comments
Authors & Categories
Search & Filter
🎓 Key Concepts Demonstrated
1. Nested Resources
2. Resource Relationships
One-to-Many: Author has many Posts
One-to-Many: Post has many Comments
Many-to-Many: Posts have many Tags
Self-Referential: Comments reply to Comments (threading)
# List posts
curl http://localhost:8000/api/v1/posts
# Get specific post
curl http://localhost:8000/api/v1/posts/1
# Create post
curl -X POST http://localhost:8000/api/v1/posts \
-H "Content-Type: application/json" \
-d '{
"title": "My First Blog Post",
"slug": "my-first-blog-post",
"content": "# Hello World\n\nThis is my first post!",
"excerpt": "Introduction to my blog",
"author_id": 1,
"category_id": 1,
"tags": ["intro", "welcome"],
"status": "published"
}'
# Update post
curl -X PUT http://localhost:8000/api/v1/posts/1 \
-H "Content-Type: application/json" \
-d '{
"title": "Updated Title",
"content": "Updated content...",
"status": "published"
}'
# List post comments
curl http://localhost:8000/api/v1/posts/1/comments
# Add comment
curl -X POST http://localhost:8000/api/v1/posts/1/comments \
-H "Content-Type: application/json" \
-d '{
"content": "Great article!",
"author_id": 3
}'
# Reply to comment (threaded)
curl -X POST http://localhost:8000/api/v1/posts/1/comments \
-H "Content-Type: application/json" \
-d '{
"content": "Thanks!",
"author_id": 1,
"parent_id": 1
}'
# List authors
curl http://localhost:8000/api/v1/authors
# Get author profile
curl http://localhost:8000/api/v1/authors/1
# Get author's posts
curl http://localhost:8000/api/v1/authors/1/posts
# List categories
curl http://localhost:8000/api/v1/categories
# Get category posts
curl http://localhost:8000/api/v1/categories/tutorial/posts