facil.io

facil.io

Web applications in C — evented HTTP, WebSockets, Pub/Sub and TLS in one library.

0.8.x edge

Upcoming release — the fio-stl library: single-header C core, IO reactor, HTTP, Pub/Sub and TLS 1.3.

Open documentation →
0.7.x stable

Stable release — the classic evented framework: HTTP, WebSockets, Pub/Sub, Redis.

Open documentation →
0.6.x legacy

Legacy release — kept for reference.

Open documentation →

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

c
#define FIO_IO   /* the IO reactor */
#define FIO_HTTP /* the HTTP / WebSocket / SSE module */
#include "fio-stl.h"

// We'll use this callback in `fio_http_listen`, to handle HTTP requests
void on_request(fio_http_s *h);

// Listen to HTTP requests and start facil.io
int main(void) {
  // listen on port 3000 and any available network binding
  fio_http_listen("0.0.0.0:3000", .on_http = on_request, .log = 1);
  // start the server
  fio_io_start(0); /* or fio_io_start(4) for 4 worker processes */
}

// Easy HTTP handling
void on_request(fio_http_s *h) {
  fio_http_cookie_set(h,
                      .name = FIO_STR_INFO1("my_cookie"),
                      .value = FIO_STR_INFO1("data"));
  fio_http_response_header_set(h,
                               FIO_STR_INFO1("content-type"),
                               FIO_STR_INFO1("text/plain"));
  fio_http_response_header_set(h,
                               FIO_STR_INFO1("x-data"),
                               FIO_STR_INFO1("my data"));
  fio_http_write(h, .buf = "Hello World!\r\n", .len = 14, .finish = 1);
}

(Written using version 0.8.x)

#Creating a Web Application Using facil.io

Starting a new application with facil.io is as easy as copying a file - facil.io is a header file library, with no build step and no dependencies to install.

Download facil.io from GitHub and copy either the single-header fio-stl.h or the modular fio-stl folder into your project:

bash
curl -L -o fio-stl.h https://raw.githubusercontent.com/facil-io/cstl/master/fio-stl.h

Then enable the modules you need and include the header:

c
#define FIO_IO   /* the IO reactor */
#define FIO_HTTP /* the HTTP / WebSocket / SSE module */
#include "fio-stl.h" /* or "fio-stl/include.h" when using the folder */

Done. Write your code and compile.

Looking for the classic 0.7.x API and its application template script? They are still available from the original facil.io repository.


#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 :-)

Pull requests should edit the modular sources in the fio-stl folder - the makefile regenerates the single-header fio-stl.h automatically. See the contribution guide for details.

Hit me up if you want to: