# libhttp

A basic HTTP Framework

## Installation

```
sudo make install
```

## Usage

```c
#define LIB_HTTP_IMPL
#include <libhttp.h>

http_response_t do_handle(http_request_t *request) {
  http_response_t response = http_response_create(HTTP_STATUS_OK);
  http_header_set(&response, "Content-Type", "text/html");
  http_response_body(&response, "<h1>Hello, World!</h1>", 22);
  return response;
}

int main(void) {
  http_t *http = http_init();
  http_on_request(http, do_handle);
  if (http_bind(http, "0.0.0.0", 80, NULL, 0) != HTTP_ERR_OK) {
    printf("failed to bind port :80\n");
    http_cleanup(http);
    return 1;
  }
  if (http_listen(http) == HTTP_ERR_OK) {
    printf("server is running on port :80\n");
    pause();
  }
  http_close(http);
  printf("server stopped\n");
  http_cleanup(http);
  return 0;
}
```
