facil.io - The C Web Application Framework

I used this library (including the HTTP server) on Linux, Mac OS X and FreeBSD (I had to edit the makefile for each environment).

A Web application in C? It's as easy as...

#include "http.h" /* the HTTP facil.io extension */

// We'll use this callback in `http_listen`, to handles HTTP requests
void on_request(http_s *request);

// These will contain pre-allocated values that we will use often

// Listen to HTTP requests and start facil.io
int main(void) {
  // allocating values we use often
  HTTP_HEADER_X_DATA = fiobj_str_new("X-Data", 6);
  // listen on port 3000 and any available network binding (NULL ==
  http_listen("3000", NULL, .on_request = on_request, .log = 1);
  // start the server
  fio_start(.threads = 1);
  // deallocating the common values

// Easy HTTP handling
void on_request(http_s *request) {
  http_set_cookie(request, .name = "my_cookie", .name_len = 9, .value = "data",
                  .value_len = 4);
  http_set_header(request, HTTP_HEADER_CONTENT_TYPE,
                  http_mimetype_find("txt", 3));
  http_set_header(request, HTTP_HEADER_X_DATA, fiobj_str_new("my data", 7));
  http_send_body(request, "Hello World!\r\n", 14);

(Written using version 0.7.0)

Creating a Web Application Using facil.io

Starting a new application with facil.io is as easy as downloading a copy of facil.io from GitHub.

To make things easier, a script is provided.

bash <(curl -s https://raw.githubusercontent.com/boazsegev/facil.io/master/scripts/new/app) appname

By default, this script downloads the latest release, which may or may not be what you want.

It's possible to download a specific release or branch, (for example, the latest 0.6.x release, 0.6.4) using FIO_RELEASE or FIO_BRANCH.

i.e., download the latest stable release, version 0.6.4:

FIO_RELEASE=0.6.4 bash <(curl -s https://raw.githubusercontent.com/boazsegev/facil.io/master/scripts/new/app) appname

i.e., or download the latest development (edge) version from the master branch:

FIO_BRANCH=master bash <(curl -s https://raw.githubusercontent.com/boazsegev/facil.io/master/scripts/new/app) appname

Forking, Contributing and all that Jazz

Sure, why not.

If you encounter any issues, open an issue (or, even better, a pull request with a fix) - that would be great :-)

Hit me up if you want to: