Skip to content
Plaristote edited this page Nov 4, 2015 · 18 revisions

Introduction to Crails Framework

Why Crails framework ?

Because Rails' approach to web framework is not all wrong. We aim at providing a similar - although much simpler environment to the developers.

Crails is fast and very light. And it helps you work with the fastest libraries around (for instance, the ODB ORM.

How does it work

Crails is built upon the cppnetlib, which is a boost powered library that implements the http server and parser that our framework uses. Crails uses the cppnetlib to implement the request pipe, explained in the following diagram:

  +------------+
  | cpp netlib |
  |   server   |
  +------------+
        |
 Exception Catcher ----------------|
        |                          |
        |                          v
        v                Prepare a 500 response.
  Request Parsers           Ends the request.
        |
        |
        v
 +--------------+
 |     Data     |
 |   (cookies,  |
 |uri parameters|          *Request Parsers*
 | http headers)|          They read data from the http
 +--------------+          request, and store them in a
         |                 more accessible fashion.
         v
+-----------------+        They run one after the other,
|    Multipart    |        util one of them declares the
|(multipart forms,|        parsing over.
|  file uploads)  |
+-----------------+        Parameters are stored in a
         |                 boost::property_tree::ptree,
         v                 which the developer can then
+------------------+       access in a Controller through
|       Form       |       the `params` attribute.
|(urlencoded forms)| 
+------------------+ 
         |
         v
+------------------+
|       JSON       |
|(application/json)|
+------------------+
         |
+------------------+
|       ...        |
| you may add your |
|   own parsers    |
+------------------+
         |
         |
  Request Handlers
         |
         |
         v
+------------------+              +--------------+                      +-----------------+
|  Action Handler  |------------->|    Router    |--- route matches --> | Your controller |
+------------------+              +--------------+                      +-----------------+
                                          |                                      |
                                          v                                      v
                                    no route match                  cppnetlib sends the response
                                          |
         |--------------------------------|
         |
         v               *File handler*                   
+------------------+     Though the File handler can
|   File Handler   |     serve your assets, it is not
+------------------+     designed for production. We
         |               encourage you to use, for
         v               instance, nginx as a load
+------------------+     balancer and a file server.
|       ...        |
| you may add your |
|   own handlers   |
+------------------+
  cppnetlib sends
    the response

What does it do for me ?

Asset pipeline

Crails comes with an asset pipeline, based on a Guardfile. It can compile your Javascript, Coffeescript and SCSS files.

C++ View Templates

Crails is the first web framework to come with C++ templates. There are two modules, html and json, which, when included to your project, add support for the ecpp and cjson template files. // TODO write documentation for ecpp and cjson... link it here.

Security considerations

Crails comes with SSL support, cookie encryption and CSRF tokens.