titanium

titanium is a Rack based application server that follows RESTful principals to automatically interact with a document-oriented database. Additionally, titanium uses JSON to return information back to the consumer.

What are some possible uses for titanium?

The most common choice is for simple AJAX enabled web applications; however, the list below includes additional ideas.

  • to develop web applications with only HTML and JavaScript

  • to develop a content management system with an administrative interface for another system

  • to prototype a web page/site

  • to provide simple storage access to anything with the ability to make HTTP requests

  • shared hosting providers could add titanium to their Rack enabled web servers to allow customers the ability to create web applications with storage just by using HTML and JavaScript

How does titanium work?

Standard HTTP protocol conventions are used to determine what database actions to perform.

Below are examples of HTTP requests and a brief explanation of the database action that will be executed.

Inserts a car into the datastore. The data saved is determined from the POST parameters. Returns the key of the item saved.
  POST /foo/car

Updates the car with key 55. The data updated is taken from the PUT parameters. Returns the key of the item updated.
  PUT /foo/car@55

Returns all cars
  GET /foo/car 

Returns a single car who's key is equal to 55.
  GET /foo/car@55

Returns all Honda car's made in 2009
  GET /foo/car?year=2009&make=Honda

Returns all car's made in 2009 sorted by make in ascending order
  GET /foo/car?year=2009&sort-field=make&sort-order=asc

Returns the second page of five results of Honda car's made in 2009 sorted by model in descending order
  GET /foo/car?year=2009&make=Honda&sort-field=model&sort-order=desc&limit=5&offset=5

Deletes the car with key 55
  DELETE /foo/car@55

Deletes all cars
  DELETE /foo/car

Getting started

Follow the instructions below to start developing a site using titanium.

Create the folder structure below for the web application’s source.

myapp
myapp/public
myapp/tmp

Create an index.html file in the myapp/public folder.

Create a rackup file at myapp/config.ru with the following contents. This file is used to tell the titanium server where the web application resides. Make sure to use the full path to the myapp/public folder, and make sure to always use forward slashes.

require 'titanium'
run Titanium::Server.new("/var/www/myapp/public")

Or, for Windows

require 'titanium'
run Titanium::Server.new("c:/www/myapp/public")

Download and install Ruby at www.ruby-lang.org/en/downloads.

Download and install SQLite3 for Ruby. Typically this involves downloading a precompiled set of binaries from sqlite.org/download.html, and unpacking the download into the ruby/bin directory.

Install the titanium gem with:

sudo gem install cfrederick-titanium

Run titanium using the config.ru created above.

rackup /var/www/myapp/config.ru

View at: localhost:9292