so://phie

tpee

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/http

2

3A basic HTTP Framework

4

5## Installation

6

7```

8sudo make install

9```

10

11## Usage

12

13```c

14#define SO_HTTP_IMPL

15#include <so/http.h>

16

17#define HOST "0.0.0.0"

18#define PORT 80

19

20HTTP_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}

28

29int 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```