MicroHTTP is a minimalist HTTP server written in pure C with no external dependencies.
It's mainly designed for educational purposes or lightweight embedded use cases, allowing you to understand how HTTP servers work under the hood.
- Supports
GET
andPOST
requests - Custom route handlers
- Parses headers and body manually (no HTTP libraries used)
- Works with plain text and JSON payloads
- Zero external dependencies — just standard C and sockets
microhttp/
├── microhttp.h # Public API header
├── microhttp.c # HTTP server implementation
└── main.c # Example app using the library
gcc main.c microhttp.c -o microhttp_server
./microhttp_server
The server will start and listen on http://localhost:8080
.
curl http://localhost:8080/
curl -X POST http://localhost:8080/submit \
-H "Content-Type: application/json" \
-d '{"nome":"Marco", "cognome":"Barca"}'
Server response:
Nome: Marco
Cognome: Barca
- Only handles one request at a time (no concurrency)
- No HTTPS (pure HTTP only)
- No routing wildcards or query parameter parsing (yet)
- Only supports simple body formats (text / raw JSON)
In main.c
:
void handle_root(HttpRequest *req, HttpResponse *res) {
http_send(res, 200, "text/plain", "Welcome to microhttp!");
}
void handle_post(HttpRequest *req, HttpResponse *res) {
http_send(res, 200, "application/json", "{\"status\":\"ok\"}");
}
int main() {
http_server_start(8080);
http_on("GET", "/", handle_root);
http_on("POST", "/submit", handle_post);
http_server_run();
}
- Multithreading or forking to handle concurrent clients
- Support wildcard routes:
/user/:id
- Handle query strings and URL decoding
- Static file serving (HTML, CSS, etc.)
MIT License — free to use, modify and share.