https://github.com/shorya-1012/http_server
A HTTP Server made from scratch in C++.
https://github.com/shorya-1012/http_server
cpp http-server
Last synced: 6 months ago
JSON representation
A HTTP Server made from scratch in C++.
- Host: GitHub
- URL: https://github.com/shorya-1012/http_server
- Owner: shorya-1012
- Created: 2025-05-31T16:24:39.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-06T18:00:51.000Z (about 1 year ago)
- Last Synced: 2025-06-06T19:18:53.194Z (about 1 year ago)
- Topics: cpp, http-server
- Language: C++
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple HTTP Server in C++
This is a basic Multi-Threaded HTTP Server implemented from scratch in C++ with support for serving HTML, plain text, and CSS files.
## Features
- Handle multiple routes
- Implements Multi-Threading using a Thread Pool.
- Serve static HTML and CSS files
- Send plain text responses
## Build Instructions
1. Clone the repository:
```bash
git clone https://github.com/shorya-1012/http_server.git
cd http-server
````
2. Build the project using CMake:
```bash
mkdir build && cd build
cmake ..
make
```
3. Run the server:
```bash
./server
```
4. Open your browser and navigate to:
* `http://localhost:8080/`
## Example Main Function
```cpp
int main(int argc, char *argv[]) {
Server server;
server.add_routes("/", [](HttpRequest &req, HttpResponse &res) {
res.send_html(200, "../templates/index.html");
});
server.add_routes("/about", [](HttpRequest &req, HttpResponse &res) {
res.send_text(200, "Welcome to About Page");
});
server.add_routes("/foo", [](HttpRequest &req, HttpResponse &res) {
res.send_text(200, "BAR");
});
server.run(8080);
return 0;
}
```
## Dependencies
No external dependencies. Uses only standard C++ and POSIX system calls (`socket`, `fork`, `read`, `write`, etc.).