A low-key HTTP micro-framework for people who hate web bloat
git clone git://soophie.de/tpee
blob: ab034061b77c2d0ce18761ef106ee9f36c1b1412 (803 bytes)[doc][blame][raw]
1
# so/http3
A basic HTTP Framework5
## Installation7
```8
sudo make install9
```11
## Usage13
```c14
#define SO_HTTP_IMPL15
#include <so/http.h>17
#define HOST "0.0.0.0"18
#define PORT 8020
HTTP_GET("/", index_page) {21
(void) req;22
http_resp_t resp = http_resp_create(HTTP_STATUS_OK);23
http_resp_header(&resp, "Content-Type", "text/html");24
char *html = "<h1>Hello, World!</h1>";25
http_resp_body(&resp, html, strlen(html));26
return resp;27
}29
int main(void) {30
http_t *http = http_init();31
http_err_t err = http_bind_listen(http, HOST, PORT);32
if (err == HTTP_ERR_OK) {33
printf("server is running on %s:%d\n", HOST, PORT);34
pause();35
http_close(http);36
}37
else {38
printf("failed to start server on %s:%d\n", HOST, PORT);39
}40
printf("server stopped\n");41
http_cleanup(http);42
return 0;43
}44
```