# so/http

A basic HTTP Framework

## Installation

```
sudo make install
```

## Usage

```c
#define LIB_HTTP_IMPL
#include <so/http.h>

#define HOST "0.0.0.0"
#define PORT 80

HTTP_GET("/", index_page) {
  (void) req;
  http_resp_t resp = http_resp_create(HTTP_STATUS_OK);
  http_resp_header(&resp, "Content-Type", "text/html");
  char *html = "<h1>Hello, World!</h1>";
  http_resp_body(&resp, html, strlen(html));
  return resp;
}

int main(void) {
  http_t *http = http_init();
  http_err_t err = http_bind_listen(http, HOST, PORT);
  if (err == HTTP_ERR_OK) {
    printf("server is running on %s:%d\n", HOST, PORT);
    pause();
    http_close(http);
  }
  else {
    printf("failed to start server on %s:%d\n", HOST, PORT);
  }
  printf("server stopped\n");
  http_cleanup(http);
  return 0;
}
```
