This project aims to be a simple and fast HTTP micro framework written in C.
git clone https://github.com/AllanDantas21/MicroHTTP.git && cd MicroHTTPmake -f Makefile.lib./examples/simple_serverTo create an HTTP server, you need to include the necessary headers and configure the server:
#include "includes/api/httpc.h"
int main(void) {
// Initialize the framework
if (httpc_init() != 0) {
return 1;
}
// Configure the server
httpc_config_t config = {
.port = 8080,
.backlog = 10,
.max_clients = 10
};
if (httpc_configure(&config) != 0) {
httpc_cleanup();
return 1;
}
// Add routes here
// Start the server
return httpc_start();
}Routes are defined using the httpc_add_route function. Each route needs an HTTP method, a path, and a handler function:
// Handler for the main route
char* handle_home(const char* buffer) {
const char* body = "<html><body><h1>Welcome!</h1></body></html>";
char* response = build_response(200, "text/html", body);
return response;
}
// Add the route
httpc_add_route(&g_router, "GET", "", handle_home);See the examples/simple_server.c file for a complete implementation example with multiple routes and JSON handling.