A low-key HTTP micro-framework for people who hate web bloat
git clone git://soophie.de/tpee
blob: 691225d64ee0520a3edaece90abb43e236837ab2 (828 bytes)[doc][blame][raw]
1
# libhttp3
A basic HTTP Framework5
## Installation7
```8
sudo make install9
```11
## Usage13
```c14
#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;22
}24
int main(void) {25
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);30
return 1;31
}32
if (http_listen(http) == HTTP_ERR_OK) {33
printf("server is running on port :80\n");34
pause();35
}36
http_close(http);37
printf("server stopped\n");38
http_cleanup(http);39
return 0;40
}41
```