Skip to content

kenzhengguan/Tofu

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tofu

Travis CI

Tofu is a framework for building web applications in C with as minimal effort as possible, allowing simple web applications to be created rapidly and with few lines of C code.

Tofu is web server agnostic, which means that applications written using the Tofu API can be run on a wide variety of backend web servers with very little work on the app developer side.

Attention: Tofu is highly experimental software, take it as a proof-of-concept.

GETTING STARTED

Put the following code into hi.c:

#include <tofu.h>

tofu_rep_t *hello(tofu_req_t *req, void *argp) {
  tofu_rep_t *rep = tofu_rep_init();

  tofu_head(rep, "Content-Type", "text/html");
  tofu_write(rep, "Hello World!");

  return rep;
}

int main() {
  char *opts[] = { "0.0.0.0", "8080" };
  tofu_ctx_t *ctx = tofu_ctx_init(TOFU_EVHTTP, opts);

  tofu_handle_with(ctx, GET, "/hi", hello, 0x0);
  tofu_loop(ctx);

  return 0;
}

compile and run with:

$ cc -o hi hi.c -ltofu
$ ./hi

then visit http://0.0.0.0:8080/hi with your browser.

For more info have a look at the full documentation.

EXTRA LIBRARIES

Tofu does not provide any advanced functionalities that may be useful when developing web applications. Here's a list of useful external libraries to extend your Tofu applications (or any other software written in C/C++):

  • houdini is a simple API for escaping and unescaping text for the web.
  • amaca is a tiny template engine which natively supports Lua scripting.
  • ctpl is another template library written in C.
  • jansson is a C library for encoding, decoding and manipulating JSON data.
  • discount is an implementation of John Gruber's Markdown markup language.
  • hiredis is a minimalistic C client library for the Redis database.
  • libmongo-client is an alternative C driver for MongoDB.

If you know any other library, please let me know.

DEPENDENCIES

  • libcurl (only for the tests)
  • libfcgi (only for the fcgi backend)
  • libevent (>= 2.0) (only for the evhttp backend)
  • jansson (only for the zmq backend)
  • zeromq (only for the zmq backend)

BUILDING

Tofu is distributed as source code. Build with:

$ ./autogen.sh
$ ./configure
$ make
# make install

Note that, by default, all the backends are built.

To build the documentation:

$ make html

COPYRIGHT

Copyright (C) 2011 Alessandro Ghedini al3xbio@gmail.com

See COPYING for the license.