balde
master
A microframework for C based on GLib.
|
This is a quick guide to get users started with balde. At the end of this guide you should be able to get a simple balde example running.
If you are used to write C applications, it will be quite easy for you to start creating simple web applications with balde.
At the end of each section, you will find links to detailed documentation about each topic.
Enjoy!
TODO: add asciinema.org video here
To install balde you must download it first. Pick the latest release, and download it to your computer. After downloading, extract it with some tool like tar
.
To run this example, the only required dependencies are GLib >= 2.35
, shared-mime-info
(that is usually installed with GLib
), GNU Make
and GCC
. Other dependencies and features are listed in the Installation section of the documentation.
To install it, from the extracted directory, run:
$ ./configure $ make # or gmake, if you are running some flavour of BSD # make install # or sudo make install, if applicable
See the Installation section for more information about how to install balde.
This is the simplest web application that someone can build with balde, a "hello world":
Save its content to a file called hello.c
in your current directory. This file can be found in the examples/
directory of the balde tarball and/or Git repository.
This example is mostly self-explanatory, but lets go into the details of it, to make things even clearer.
First of all, you must include the balde header:
After that, you can declare a view, to reply to requests. As this is a simple example, we are not going to add the prototype of the function, just implement it directly:
The hello
function is a typical balde view. It gets a balde application context and a balde request context, and returns a balde response context.
The simple view of the example just returns a response with a hardcoded string:
The main
function is the function that is called when any C
application is started:
At the begin of the function, you should initialize a balde application context:
After that, you should register the previously defined hello
function as a view for this application context, accepting GET
requests at /
:
Now that a view is registered in the application context, you can finally run the application main loop:
When the main loop exits, you must free the memory used by the application context:
The main
functions for balde will almost always return 0
in the end:
This information should be enough to get started.
See the Application Development section for more information about how to write balde applications.
To build the example, you will want to use pkg-config to find the balde library and headers, that were previously installed, and pass that info to the compiler.
$ gcc -o hello $(pkg-config --libs --cflags balde) hello.c
Or, if you use clang
:
$ clang -o hello $(pkg-config --libs --cflags balde) hello.c
See the Application Structure section for more information about how to distribute/build your balde applications.
balde comes with an embedded HTTP server, that can be used when you are developing your applications.
$ ./hello --runserver * Running on http://127.0.0.1:8080/ (threads: 10)
Visit the given URL with your web browser, and you should see the expected message!
See the Application Command Line Interface section for more information about the usage of the command line interface provided by the balde library.
After having the example running in your local machine, you may want to deploy it to a public server. See the Application Deployment section for deployment guides.