libhttp
A basic HTTP Framework
Installation
sudo make install
Usage
#define LIB_HTTP_IMPL
#include <libhttp.h>
HTTP_GET("/", index_page) {
(void) req;
http_resp_t resp = http_resp_create(HTTP_STATUS_OK);
http_resp_header(&resp, "Content-Type", "text/html");
http_resp_body(&resp, "<h1>Hello, World!</h1>", 22);
return resp;
}
int main(void) {
http_t *http = http_init();
if (http_bind(http, "0.0.0.0", 80, NULL, 0) != HTTP_ERR_OK) {
printf("failed to bind port :80\n");
http_cleanup(http);
return 1;
}
if (http_listen(http) == HTTP_ERR_OK) {
printf("server is running on port :80\n");
pause();
}
http_close(http);
printf("server stopped\n");
http_cleanup(http);
return 0;
}