A high-performance, multithreaded HTTP/1.1 server built from scratch in modern C++. Designed with real-world backend concepts like routing, middleware, thread pooling, static file serving, and graceful shutdown.
curl http://localhost:8080/health
curl http://localhost:8080/users
curl -X POST http://localhost:8080/users \
-H "Content-Type: application/json" \
-d '{"name":"Alice","email":"alice@example.com"}'
curl http://localhost:8080/users/1
curl -X DELETE http://localhost:8080/users/1
curl "http://localhost:8080/echo?msg=hello"- HTTP/1.1 server implementation using low-level socket programming
- Multithreaded architecture using a fixed-size thread pool
- Keep-Alive connection support for performance optimization
- Graceful shutdown handling (SIGINT / SIGTERM)
- Custom Router with dynamic route support (
/users/:id) - Middleware pipeline (inspired by Express.js / Gin)
- Modular and scalable project structure
-
Request logging (thread-safe logger)
-
CORS handling
-
Security headers:
X-Frame-OptionsX-Content-Type-OptionsX-XSS-Protection
-
Rate limiting (per-IP sliding window)
- Serves files from
/staticdirectory - Automatic MIME type detection
- In-memory caching (reduces disk I/O)
- Directory fallback (
index.html)
GET /healthβ Health checkGET /usersβ Get all usersPOST /usersβ Create userGET /users/:idβ Get user by IDDELETE /users/:idβ Delete userGET /echo?msg=helloβ Query param echo
- Socket programming (
bind,listen,accept) - Multithreading (
std::thread,mutex,condition_variable) - Atomic operations
- File system operations (
std::filesystem) - Signal handling (
SIGINT,SIGTERM,SIGPIPE) - Memory-safe design (RAII principles)
cpp-http-server/
βββ src/
β βββ main.cpp
βββ include/
β βββ config.h
β βββ logger.h
β βββ thread_pool.h
β βββ http_types.h
β βββ http_parser.h
β βββ router.h
β βββ middleware.h
β βββ connection_handler.h
β βββ static_server.h
β βββ http_server.h
βββ static/
β βββ index.html
βββ screenshots/
βββ Makefile
βββ README.md
βββ LICENSE
βββ .gitignore
make./serverServer runs on:
http://localhost:8080
curl http://localhost:8080/healthcurl -X POST http://localhost:8080/users \
-H "Content-Type: application/json" \
-d '{"name":"Alice","email":"alice@example.com"}'curl http://localhost:8080/userscurl http://localhost:8080/users/1curl -X DELETE http://localhost:8080/users/1curl http://localhost:8080/static- Client sends HTTP request
- Server accepts connection and assigns it to thread pool
- Request is parsed into structured format
- Middleware pipeline processes request
- Router matches endpoint
- Handler or static server generates response
- Response is sent back with keep-alive support
Unlike basic projects, this server implements real backend internals:
- No frameworks used
- Built completely from scratch
- Demonstrates understanding of system-level programming
- Covers real-world backend concepts used in production systems
- HTTPS (SSL/TLS support)
- JSON parser integration
- Database support (MongoDB / SQLite)
- File upload handling
- Load balancing
- Performance benchmarking
Sandeep Raj Aspiring Software Engineer | MERN + C++ Backend Developer
If you like this project, consider giving it a β on GitHub! ject, consider giving it a β on GitHub!


