Example Application

timClicks edited this page Aug 10, 2012 · 2 revisions

Here’s the code necessary to write a very simple CB app. Let’s suppose we have a database of library books, and want to write an application for viewing them.

First, we create a new Chicago Boss project. Under the Chicago Boss directory:

$ make app PROJECT=simple

This creates the directory simple on the same level as the Chicago Boss installation.

Next we define a library_book model. Under the simple directory:


-module(library_book, [Id, Title, AuthorName]).

Next we define a controller for pulling records from the database. We prefix the filename of our controller with the name of our project.


-module(simple_library_book_controller, [Req]).

list('GET', []) ->
    LibraryBooks = boss_db:find(library_book, []),
    {ok, [{books, LibraryBooks}]}.

Finally we make a template file that puts all of the data into a pretty table.


{% for book in books %}
<tr><td>{{ book.title }}</td>
    <td>{{ book.author_name }}</td>
{% endfor %}

And that’s it! Visiting http://localhost:8001/library_book/list will show us all the library books in the database.

Further Tutorials

This is the most basic of introductions for ChicagoBoss, which doesn’t explain many of the unique features that make it such a great way to build web applications. The community has been developing

  • An Evening with ChicagoBoss, which explains the fundamentals of ChicagoBoss and details how to use features such as writing advanced database queries, sending and receiving email, pushing data to multiple clients in real-time with COMET and more.