so://phie

tpee

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# libhttp

2

3A basic HTTP Framework

4

5## Installation

6

7```

8sudo make install

9```

10

11## Usage

12

13```c

14#define LIB_HTTP_IMPL

15#include <libhttp.h>

16

17http_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}

23

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