Bright On Server

Bright consist of both - server and client side parts. Though it's not necessary to use both. In general your application can run with Ruby server side and Bright client side. Or Bright server side and Backbone client side.

Let's check how Bright solve main needs of web application - Routing, Content rendering and Database access.

Routing

Routing explained in the BrRequest section. Here is just a small example:

br()
  ->request()
    ->route('/index.html', function() {
        // display homepage
      })
    ->route('/order.html?client=([0-9]+)', function($matches) {
        // display order of client $matches[1]
      })
    ->routeGET('/pay.html', function() {
        // display payment page
      })
    ->routePOST('/pay.html', function() {
        // handle POST to pay.html
      })
    ->route('POST', '/pay.html', function() {
        // handle POST to pay.html - same as prior rule
      })
    ->routeIndex(function() {
        // handle request to root url of your site
      })
    ->routeDefault()
;

Content rendering

Rendering explained in the BrRenderer section. Here is just a small example:

br()->renderer()->fetch('index.html');

Database access

Database access explained in the BrDatabase section. Here is just a small example:

$idx = 1;
$rows = br()->db()->getRows('SELECT * FROM some_table');
foreach($rows as $row) {
  br()->db()->runQuery('UPDATE some_table SET field = ? WHERE id = ?', $idx++, $row['id']);
}