A Minimal cross-platform HTTP server in C.
- Opens a 8080 port.
- Provides a Webserver API with routes.
- Uses sockets (
sys/socket.h
,netinet/in.h
). - Responds with a JSON or HTML.
- Supports Client connections in a loop (handle requests).
- Returns (ok) --> HTTP 200 status code.
A limited Procedure language adapted to modular-structure
like modern frameworks: Nest, Express.
- Idea: Use include headers to import functions as componentized-style and build a makefile to construct the procedure line logic to compile the project.
webserver-in-C/
├── src/
│ ├── handlers/ # Request handlers
│ ├── routes/ # Route definitions
│ ├── server/ # Server logic
│ └── utils/ # Utility functions
├── obj/ # Compiled objects
├── Makefile # Build configuration
└── src/main.c # Entry point
Routes:
- GET / - Welcome message
- GET /api - Basic API response
- GET /os - OS information
- GET /system - System information
Environment:
- Install MSYS2 (recommended):
- Download from: MSYS2 Installer
- Follow installation instructions
- In MSYS2 terminal, run:
pacman -Syu pacman -S --needed base-devel mingw-w64-x86_64-toolchain
- Add to PATH:
C:\msys64\mingw64\bin
Build and Run:
# Build the project
make
# Build and run the server
make run
# Clean build artifacts
make clean
Tips: Run in Background (PowerShell):
# Start server in background
Start-Job -ScriptBlock { .\webserver.exe }
# Check if the job is running
Get-Job
# Stop server
Stop-Job -Id <JOB_ID>
Remove-Job -Id <JOB_ID>
Environment:
- Install build tools:
sudo apt update sudo apt install build-essential
Build and Run:
# Build the project
make
# Build and run the server
make run
# Clean build artifacts
make clean
Tips: Run in Background:
# Start server in background
./webserver &
# Check running processes
ps aux | grep webserver
# To stop the server
kill $(pgrep webserver)
Environment:
- Install Homebrew: brew install
- Install build tools:
brew install gcc make
Build and Run:
# Build the project
make
# Build and run the server
make run
# Clean build artifacts
make clean