Blog API Documentation
This document provides information about the Blog API implementation for the GNX Software Solutions website.
Overview
The Blog API is a RESTful API built with Django REST Framework that provides endpoints for managing blog posts, categories, authors, tags, and comments.
Backend Setup
Models
The blog app includes the following models:
- BlogAuthor - Stores information about blog post authors
- BlogCategory - Categories for organizing blog posts
- BlogTag - Tags for additional post categorization
- BlogPost - The main blog post model
- BlogComment - Comments on blog posts (with moderation support)
API Endpoints
Base URL: /api/blog/
Blog Posts
-
GET /api/blog/posts/- List all blog posts (with pagination and filtering)- Query parameters:
category- Filter by category slugtag- Filter by tag slugauthor- Filter by author IDsearch- Search in title, content, and excerptfeatured- Filter featured postsordering- Sort by fields (e.g.,-published_at,views_count)page- Page numberpage_size- Items per page (default: 9)
- Query parameters:
-
GET /api/blog/posts/{slug}/- Get a single blog post by slug -
GET /api/blog/posts/featured/- Get featured blog posts -
GET /api/blog/posts/latest/?limit=5- Get latest blog posts -
GET /api/blog/posts/popular/?limit=5- Get popular posts by views -
GET /api/blog/posts/{id}/related/- Get related posts
Categories
GET /api/blog/categories/- List all categoriesGET /api/blog/categories/{slug}/- Get a single category by slugGET /api/blog/categories/with_posts/- Get categories that have published posts
Authors
GET /api/blog/authors/- List all authorsGET /api/blog/authors/{id}/- Get a single authorGET /api/blog/authors/{id}/posts/- Get all posts by an author
Tags
GET /api/blog/tags/- List all tagsGET /api/blog/tags/{slug}/- Get a single tag by slugGET /api/blog/tags/{slug}/posts/- Get all posts with a specific tag
Comments
GET /api/blog/comments/?post={post_id}- Get comments for a postPOST /api/blog/comments/- Create a new comment (requires moderation)
Management Commands
Populate Blog Data
To populate the database with sample blog data:
python manage.py populate_blog
This command creates:
- 4 sample authors
- 6 blog categories
- 16 tags
- 8 sample blog posts with full content
Frontend Integration
API Service
Location: /lib/api/blogService.ts
The service provides functions for:
- Fetching blog posts (with filtering)
- Getting single posts by slug
- Fetching categories, tags, and authors
- Getting featured, latest, and popular posts
- Managing comments
Custom Hooks
Location: /lib/hooks/useBlog.ts
Available hooks:
useBlogPosts(params)- Fetch paginated list of postsuseBlogPost(slug)- Fetch a single postuseFeaturedPosts()- Fetch featured postsuseLatestPosts(limit)- Fetch latest postsusePopularPosts(limit)- Fetch popular postsuseBlogCategories()- Fetch all categoriesuseBlogTags()- Fetch all tagsuseBlogAuthors()- Fetch all authors
Components
The following components have been updated to use the API:
- PostFilterButtons - Fetches categories from API
- PostFilterItems - Fetches and filters blog posts by category
- BlogSingle - Fetches individual post by slug from URL params
- LatestPost - Fetches latest posts for the slider
Usage Examples
Fetching All Posts
const { posts, loading, error, pagination } = useBlogPosts({
category: 'enterprise-software',
page_size: 9
});
Fetching a Single Post
const { post, loading, error } = useBlogPost('api-first-approach-to-system-integration');
Fetching Latest Posts
const { posts, loading, error } = useLatestPosts(5);
Features
Backend Features
- Pagination - All list endpoints support pagination
- Filtering - Filter posts by category, tag, author, and search
- Ordering - Sort posts by date, views, etc.
- View Tracking - Automatically increment view count when a post is viewed
- Related Posts - Automatically suggest related posts from the same category
- Comment Moderation - Comments require approval before being visible
- SEO Support - Meta descriptions and keywords for each post
- Reading Time - Estimated reading time for posts
- Tags System - Flexible tagging for better categorization
Frontend Features
- Real-time Data - All data fetched from API
- Loading States - Proper loading indicators
- Error Handling - Graceful error handling with fallbacks
- Image Optimization - Uses Next.js Image component
- Responsive Design - Mobile-friendly layouts
- Category Filtering - Filter posts by category with smooth animations
- Social Sharing - Share posts on social media
- Related Posts - Automatically shows related posts
- SEO Friendly - Proper meta tags and structured data
Sample Data
The populated sample data includes:
Categories
- Enterprise Software
- Digital Transformation
- System Integration
- Cloud Solutions
- Security
- API Development
Sample Post Topics
- The Future of Enterprise Software Architecture
- Digital Transformation Strategies for Large Enterprises
- API-First Approach to System Integration
- Cloud Migration Best Practices for Enterprise
- Enterprise Security in the Digital Age
- Building Scalable API Architectures
- Microservices Architecture for Enterprise Applications
- Data Analytics and Business Intelligence Solutions
Notes
- All blog posts support HTML content
- Images can be uploaded or linked via URL
- Posts can be marked as featured
- Comments require moderation before being visible
- The API respects published status (unpublished posts are not returned)
- View counts are automatically tracked
- Related posts are determined by category
Future Enhancements
Potential improvements:
- Add full-text search using Elasticsearch
- Implement post series/collections
- Add newsletter subscription functionality
- Implement post scheduling
- Add analytics dashboard
- Support for multiple authors per post
- Rich text editor in admin
- Image upload and management
- Post translations/i18n support
- RSS feed generation