A low-key HTTP micro-framework for people who hate web bloat
git clone git://soophie.de/tpee
14
#define LIB_HTTP_IMPL15
#include <libhttp.h>17
http_response_t do_handle(http_request_t *request) {18
http_response_t response = http_response_create(HTTP_STATUS_OK);19
http_header_set(&response, "Content-Type", "text/html");20
http_response_body(&response, "<h1>Hello, World!</h1>", 22);21
return response;17
HTTP_GET("/", index_page) {18
(void) req;19
http_resp_t resp = http_resp_create(HTTP_STATUS_OK);20
http_resp_header(&resp, "Content-Type", "text/html");21
http_resp_body(&resp, "<h1>Hello, World!</h1>", 22);22
return resp;23
}25
int main(void) {26
http_t *http = http_init();26
http_on_request(http, do_handle);27
if (http_bind(http, "0.0.0.0", 80, NULL, 0) != HTTP_ERR_OK) {28
printf("failed to bind port :80\n");29
http_cleanup(http);