This project is a simple blog application built from scratch using our custom-built Backend Web Library for C++. It serves as a demonstration of the my web library capabilities, including HTTP server functionality, routing, JSON handling, HTML templating, and more.
This simple blog application is designed to showcase the features and capabilities of our custom web framework stack:
- Backend Web Library - The main web framework
- HTTP Server Library - Custom HTTP server implementation
- Socket Library - Low-level networking
- JSON Parser Library - Custom JSON parsing and generation
- HTML Builder Library - Dynamic HTML generation
All libraries used in this project are custom-built and developed by us. No external web frameworks (like Express.js, Flask, etc.) were used.
┌─────────────────────────────────────────┐
│ Simple Blog Application │
├─────────────────────────────────────────┤
│ Backend Web Library │
├─────────────────────────────────────────┤
│ ┌─────────────┬──────────────────────┐ │
│ │ JSON Parser │ HTML Builder │ │
│ └─────────────┴──────────────────────┘ │
├─────────────────────────────────────────┤
│ HTTP Server Library │
├─────────────────────────────────────────┤
│ Socket Library │
├─────────────────────────────────────────┤
│ C++ / OS │
└─────────────────────────────────────────┘
simple-blog-from-scratch/
├── controllers/ # Request handlers
│ ├── controllers.hpp # Web page controllers
│ └── api_controllers.hpp # JSON API controllers
├── models/ # Data models
│ └── models.hpp # Blog model and file I/O
├── views/ # View layer
│ ├── views.hpp # HTML view generation
│ └── html/ # HTML templates
├── routes/ # Routing configuration
│ └── routes.hpp # Route definitions
├── middlewares/ # Custom middleware
│ └── middlewares.hpp # Authentication middleware
├── static/ # Static assets (CSS)
├── test/ # Comprehensive test suite
├── utils/ # Utility functions
├── library/ # Backend Web Library (submodule)
└── main.cpp # Application entry point
- ✅ HTTP Server - Custom HTTP/1.1 server implementation
- ✅ Routing System - Pattern-based URL routing with parameters
- ✅ Middleware Support - Authentication and request processing
- ✅ Static File Serving - CSS, images, and other assets
- ✅ JSON API - RESTful API with JSON parsing/generation
- ✅ HTML Templating - Dynamic HTML generation
- ✅ Session Management - Cookie-based authentication
- ✅ Error Handling - Comprehensive error responses
- ✅ Performance - Multi-threaded request handling
- ✅ Public Blog Viewing - Homepage with blog list and individual blog pages
- ✅ Admin Panel - Secure admin interface for blog management
- ✅ CRUD Operations - Create, Read, Update, Delete blog posts
- ✅ Authentication - Admin login with session management
- ✅ REST API - JSON API for programmatic access
- ✅ Responsive Design - Modern CSS with mobile support
- ✅ File-based Storage - Simple file-based blog storage
- Language: C++17
- Build System: CMake 3.10+
- Compiler: GCC 7+ / Clang 5+ / MSVC 2017+
-
- Main web framework with routing, middleware, and server management
- HTTP request/response handling
- Static file serving
- Error handling and logging
-
- Custom HTTP/1.1 server implementation
- Multi-threaded connection handling
- Request parsing and response generation
-
- Cross-platform socket implementation
- TCP server and client functionality
- Connection management
-
- Complete JSON parser and generator
- Type-safe JSON object manipulation
- Support for all JSON data types
-
- Dynamic HTML generation
- Template parsing and parameter substitution
- DOM-like element construction
- CMake 3.10 or higher
- C++17 compatible compiler
- Git (for submodules)
git clone <repository-url>
cd simple-blog-from-scratchgit submodule update --init --recursive./build.sh./build/simple_blogThe server will start on http://localhost:8080
- Homepage: http://localhost:8080
- Individual Blog: http://localhost:8080/blogs/1
- Admin Login: http://localhost:8080/admin/login
- Admin Dashboard: http://localhost:8080/admin/dashboard (after login)
- API Endpoint: http://localhost:8080/api/blogs
Admin Credentials: username: admin, password: password
Our custom web framework provides a complete REST API:
GET /api/blogs # Get all blogs
GET /api/blogs/{id} # Get specific blogPOST /api/blogs # Create new blog
PUT /api/blogs/{id} # Update existing blog
DELETE /api/blogs/{id} # Delete blog- Web Interface: Cookie-based sessions
- API: Bearer token (
Authorization: Bearer admin-token-123)
Get All Blogs:
curl http://localhost:8080/api/blogsCreate New Blog:
curl -X POST http://localhost:8080/api/blogs \
-H "Content-Type: application/json" \
-H "Authorization: Bearer admin-token-123" \
-d '{"title": "My Blog Post", "content": "Blog content here..."}'We've included a simple tests for the APIs:
- API Performance Testing - Concurrent request handling
- Web Page Testing - HTML endpoint verification
- Security Testing - SQL injection, XSS, and other attack vectors
- Authentication Testing - Login and session management
- Error Handling - Invalid requests and edge cases
cd test
npm install # Install test dependencies
npm test # Run complete test suiteAPI CREATE OPERATIONS:
Total Requests: 50
Success: 50 (100.00%)
Failed: 0
Average Response Time: 45.23 ms
SECURITY OPERATIONS:
Total Requests: 100
Success: 98 (98.00%) # 98% of attacks properly rejected
Failed: 2 # 2% security concerns
Demonstrate the framework's request handling capabilities:
- controllers.hpp: HTML page controllers using the HTML builder
- api_controllers.hpp: JSON API controllers using the JSON parser
Show data modeling and persistence:
- Blog class: Complete blog data model with file I/O
- Static methods: File-based database operations
Showcase dynamic HTML generation:
- Template loading: Reading HTML templates from files
- Parameter substitution: Dynamic content injection
- Component composition: Building complex pages
Demonstrate routing system:
- Pattern matching: URL patterns with parameters (
/blogs/:id) - HTTP methods: GET, POST, PUT, DELETE support
- Middleware chains: Authentication and request processing
Show static file serving:
- CSS files: Modern responsive design
- Automatic MIME types: Content-type detection
- Performance: Efficient static file delivery
auto server = std::make_unique<hh_web::web_server<>>(8080);
server->use_static("static");
server->listen(callback);router->get("/blogs/:id", Route_V(get_single_blog_controller));
router->post("/api/blogs", Route_V(auth_middleware, create_blog_controller));auto parsed_json = parse(req->get_body());
std::string title = getter::get_string(parsed_json["title"]);
auto blog_json = blog_to_json(blog);auto article_elm = std::make_shared<element>("article");
article_elm->add_child(std::make_shared<element>("h2", blog.get_title()));hh_web::exit_code admin_auth(req, res) {
// Authentication logic
return authenticated ? exit_code::CONTINUE : exit_code::EXIT;
}