Sunday 22 May 2011

Apache Cassandra & RESTful API

Over the past few months I have been heavily involved in an uber-top-secret nights & weekends project.  Is it selling a virtual Chia-Pet?  I wish.  That would be COOL.  Regardless of what it is, I jumped into the 21st century and got on board with the REST of the world.

REST:  Representational State Transfer:  http://en.wikipedia.org/wiki/Representational_State_Transfer

Without getting into too many details, what I love is how easily I was able to create a REST API that interfaces with Apache Cassandra.  I have an API that fully supports PUT / POST / GET / DELETE / SEARCH without having to write all that much code.  Admittedly, I did it with phpcassa which may not be the best, most efficient, or whatever .. but I have to say.  It works and I rarely touch the code.

Some simple concepts I implemented:

  • A resource is a 1:1 mapping to a Cassandra column family.  For example:
    • http://api.example.com/user/ is a reference to the "user" column family
  • The element that follows the resource is a 1:1 mapping to a key in a Cassandra column family
    • http://api.example.com/user/sdolgy is a reference to the key "sdolgy" in the column family "user"
What is great here is that as the design changes or new information is added to Cassandra, I am making no changes to the REST API code.  New column families, new keys ... it's all good.  Simple.  

The only issues I continue to have are the ones around security.  This is always an epic or regal battle / debate on the best way to approach and tackle this problem.  Some people are big into OAuth.  There are still security concerns over OAuth and even some references to that, despite the big boys (facebook / google / twitter / etc. ) are using it ... it doesn't mean it's more secure or the best way to secure a REST API.  For now, I have implemented my own variation and will have to revisit in the future before we launch the online CHIA PET....

Here is a good tutorial on creating a PHP REST API if you are keen to get started:


-sd

Friday 13 May 2011

hong kong or bust

some of you may know, and some of you may not, that i am currently in hong kong.  why am i here?  that's a very good question.  originally, i wasn't supposed to be here.  this is the week that the Hong Kong 5's Ice Hockey tournament is on.  I had scheduling conflicts at the time of planning a few months ago and opted out ...

fast forward to 3 weeks ago and i received an email about a player getting hurt and not being able to play.  checked my schedule and some other things and the planets had aligned.  this dolgy was going to hong kong.  there were some other reasons for the trip too.  met up with some old friends and old colleagues i haven't seen in a few years.  that was nice.

the tournament itself is as always, very well organized.  if you ever get a chance ... find Keith Fong at MegaBox and let him know that the tournament is, and you'll find out if you are ever here, one of the best organized tournaments and facilities around.

the team this year didn't fair very well.  0 wins, 4 losses.  2 goals scored.  but that's ok.  it was still fun.

the food here is brilliant.  the mtr here is brilliant.  i really do enjoy coming here... but it's time to go.  i miss this guy:


gone a week without seeing or speaking to Lucy and Jack has been very hard.  The timing and schedules and all of that haven't worked out ... been insanely busy days of hilarity and hi-jinx

British Airways.  Take me home.