Skip to content

Play Framework 2 Scala sample application that shows how to access Cassandra using the DataStax driver and its asynchronous API.

License

Notifications You must be signed in to change notification settings

magro/play2-scala-cassandra-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Play2 Scala Cassandra Sample App

This Play Framework 2 sample application shows how to access Cassandra from Scala using the DataStax Java Driver 2.0 and its asynchronous capabilities. The app allows to retrieve and store Songs (via JSON).

Usage

Start Cassandra

At first you should start Cassandra, you can just use the provided Vagrantfile (using the ) for this. If you haven't already installed Vagrant, head over to the Vagrant Installation page and get Vagrant.

The Vagrantfile uses the precise32 image, which you have to download once:

$ vagrant box add precise32 http://files.vagrantup.com/precise32.box

After that you can boot the vagrant box that will install Cassandra on its first start.

$ cd vagrant
$ vagrant up

Start the Application

As with every Play 2 application, just use play run.

How to Play

On the first start some data is inserted into Cassandra, in our case we're working with songs. To retrieve the list of stored songs point your browser to localhost:9000.

To insert another song you have to POST some json, here's how to do this with curl:

$ curl -v -X POST -H "Content-Type: application/json" \
  -d '{"title":"The Unforgiven","album":"Black Album","artist":"Metallica"}' \
  http://localhost:9000

You should get 201/Created as response status and a Location header that tells you which resource was created for the new Song.

Configuration

The hostname/IP address of the Cassandra cluster is configured in conf/application.conf. Right now only a single node is supported, this could easily be extended to take a list of nodes. The configuration is evaluated in app/Global.scala, which creates the SimpleClient to connect to Cassandra.

License

Apache 2.0

About

Play Framework 2 Scala sample application that shows how to access Cassandra using the DataStax driver and its asynchronous API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published