QUOTE: Never too old to chase dreams.

README.md - libhttp - A basic HTTP Framework

libhttp

A basic HTTP Framework
git clone git@soophie.de:/srv/git/libhttp
log | files | refs | readme

README.md (828B)


      1 # libhttp
      2 
      3 A basic HTTP Framework
      4 
      5 ## Installation
      6 
      7 ```
      8 sudo make install
      9 ```
     10 
     11 ## Usage
     12 
     13 ```c
     14 #define LIB_HTTP_IMPL
     15 #include <libhttp.h>
     16 
     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 }
     23 
     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 ```