Doodle-like REST API backed by Cassandra, used for Fribourg's University Advanced Databases System Course
The goal of the exercice is to build a REST API that will be able to create a poll, subscribe to the poll and retrieve the subsciptions.
In REST notation:
POST /rest/polls
{ "label": "Afterwork", "choices": [ "Monday", "Tuesday", "Friday" ], "email": "[email protected]" }
Returns pollId
(in Location header)
PUT /rest/polls/<pollId>
{ "name": "Benoit", "choices": [ "Monday", "Friday" ] }
Returns the updated poll, JSON encoded (see below)
GET /rest/polls/<pollId>
Returns the poll, JSON encoded
{ "poll": { "label": "Afterwork", "choices": [ "Monday", "Tuesday", "Friday" ], "email": "[email protected]", "subscribers": [ { "name": "Benoit", "choices": [ "Monday", "Friday" ] }, ... ] } }
create keyspace doodle
with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'
and strategy_options = {replication_factor:1};
create column family polls
with key_validation_class = UUIDType
and comparator = AsciiType
and default_validation_class = UTF8Type
and column_metadata = [
{column_name: label, validation_class: UTF8Type}
{column_name: email, validation_class: UTF8Type}
{column_name: choices, validation_class: UTF8Type}
];
set polls[timeuuid()]['choices'] = '[ "Monday", "Tuesday", "Friday" ]';
set polls['0488b290-c153-11e2-b652-c56eefd2b5e3']['label'] = 'Afterwork';
set polls['0488b290-c153-11e2-b652-c56eefd2b5e3']['email'] = '[email protected]';
choices
is a JSON encoded list of strings.- Polls are not intended to change often so they are put in a dedicated CF where for instance row caching could be turned on.
create column family subscribers
with key_validation_class = UUIDType
and comparator = 'CompositeType(TimeUUIDType,UTF8Type)'
and default_validation_class = UTF8Type;
set subscribers['0488b290-c153-11e2-b652-c56eefd2b5e3']['709f7180-c153-11e2-b652-c56eefd2b5e3:Benoit'] = '[ "Monday", "Friday" ]';
- The row key is the same UUID than the poll's row key.
- The column name is a TimeUUID to order the subscriptions, concatenated with (using CompositeType) a the name of the subscriber in UTF8 string
- The value is a JSON encoded list of strings representing the subscribed
choices
. Note that if the poll's administateur change thechoices
of the poll, either all the values need to be updated, or (btter) the removed choices are skipped (not displayed) at runtime.
The current implementation use Hector client as high level connection to Cassandra.