Defining the Kwwika API

02 Apr 2010

Update: Hang on a minute. You've not explained what Kwwika is!
In a really informative chat using Nurph, which has been really useful in getting feedback, it was pointed out to me by @rythie and @NeilCauldwell that I need to explain what problem Kwwika is trying to solve before asking what the API should look like.

Why do we need Kwwika?

There are loads of real-time technologies available at the moment. Almost all of them have a reasonable learning curve and require a developer to sort out server infrastructure, perform installation, do all sort of configuration and then finally get around to writing an application. In the same way that a lot of developers or organisations have moved into managed hosting for their websites, or more recently moved a lot of their IT infrastructure into the Cloud, Kwwika offers a managed and scalable real-time infrastructure so you can concentrate on building your Real-Time Rich Internet Application.

The way I'm describing Kwwika at the moment is:

Kwwika is a real-time web data sharing platform with APIs in JavaScript, Silveright, .NET, Java and C.

An example of where Kwwika could be used

Martin Tyler recently wrote a blog post that provides a great example of where a service like Kwwika would have been really useful. In the situation described in the blog post CricInfo could simply publish their cricket updates to their defined topic in Kwwika, maybe /CRICINFO/GAMES/INDIA-SOUTHAFRICA/, from a single server. They would then add a small piece of script to their game web page that subscribes to this topic and updates that web page whenever any new data is available. Users would see the real-time in-page updates and would no longer continue to hit "Refresh" to see if the score had updated. Kwwika would instead take the hit of the data transfer and push the live updates to the web page. This would take a massive load off of the CricInfo server and clearly save them a lot of time and infrastructure costs.

How will I use Kwwika?

When we launch Kwwika all you'll need to do to use the service is:

  1. Register for Kwwika via a sign up page
  2. Define your topics that you would like to publish data to in the Kwwika dashboard e.g. /PhilLeggetter/Kwwika
  3. Find some topics with information on that you are interested in using e.g. /BBC/NEWS/SPORT/FOOTBALL (doesn't exist - just an example - but how cool would that be!)
  4. Embed the Kwwika <script> tag in your web application or download the API for your chosen technology
  5. Start developing your Real-Time Rich Internet Application

    I think the great thing about this is that developers just use the Kwwika service and only ever need to care about developing their own application. Kwwika provides the server infrastructure so you don't have to.

    The Kwwika API

    I'm in the middle of defining the Kwwika API and thought this would be a great opportunity to get some early feedback. We plan to have initial releases of the API for the following technologies:

    • JavaScript
    • Java
    • .NET
    • Silverlight
    • C

    The API is really simple. It has the following functionality:

    • Connect
    • Receive connection events
    • Subscribe for data
    • Receive subscription events such as errors and data updates
    • Publish data
    • Receive data publishing events (publish success or failure)
    • Disconnect

    At the moment we have two ways of thinking about the API. The following two examples are using the JavaScript API but we plan to make the APIs virtually identical between technologies with the only differences down to following the language specific standards.

    Our main topic of discussion is around how you initiate your connection to the Kwwika service but for completeness I'll provide full examples. The first option we have is to create a Connection object using a factory method on the kwwika namespace.

    [javascript]
    var oConnection = kwwika.connect({
    "connectionStatusUpdated":function(sStatus)
    {
    document.getElementById("connectionStatus").innerHTML = sStatus;
    }
    });

    var oSubscription =
    oConnection.subscribe("/KWWIKA/LIBRARIES/JavaScriptAPI",
    {
    "topicUpdated":function(oSubscription, mUpdate)
    {
    for(var sFieldName in mUpdate)
    {
    document.getElementById("field_" + sFieldName).innerHTML = mUpdate[sFieldName];
    }
    },
    "topicError":function(oSubscription, sReason)
    {
    var sMsg = oSubscription.topicName + " error: " + sReason;
    document.getElementById("topicErrorMessage").innerHTML = sMsg;
    });

    oConnection.publish("/KWWIKA/LIBRARIES/JavaScriptAPI",
    {
    "name": "Phil Leggetter",
    "status": "Getting feedback about the Kwwika API",
    "datetime": new Date().getTime()
    },
    {
    "commandSuccess":function(oSubscription)
    {
    var sMsg = oSubscription.topicName + " message published.";
    document.getElementById("publishStatus").innerHTML = sMsg;
    },
    "commandError":function(oSubscription, sError)
    {
    var sMsg = oSubscription.topicName + " publish error: " + sError;
    document.getElementById("publishStatus").innerHTML = sMsg;
    }
    });
    [/javascript]

    In the second option is to create a new Kwwika object.

    [javascript]
    var oKwwika = new Kwwika({
    "connectionStatusUpdated":function(sStatus)
    {
    document.getElementById("connectionStatus").innerHTML = sStatus;
    }
    });

    var oSubscription =
    oKwwika.subscribe("/KWWIKA/LIBRARIES/JavaScriptAPI",
    {
    "topicUpdated":function(oSubscription, mUpdate)
    {
    for(var sFieldName in mUpdate)
    {
    document.getElementById("field_" + sFieldName).innerHTML = mUpdate[sFieldName];
    }
    },
    "topicError":function(oSubscription, sReason)
    {
    var sMsg = oSubscription.topicName + " error: " + sReason;
    document.getElementById("topicErrorMessage").innerHTML = sMsg;
    });

    oKwwika.publish("/KWWIKA/LIBRARIES/JavaScriptAPI",
    {
    "name": "Phil Leggetter",
    "status": "Getting feedback about the Kwwika API",
    "datetime": new Date().getTime()
    },
    {
    "commandSuccess":function(oSubscription)
    {
    var sMsg = oSubscription.topicName + " message published.";
    document.getElementById("publishStatus").innerHTML = sMsg;
    },
    "commandError":function(oSubscription, sError)
    {
    var sMsg = oSubscription.topicName + " publish error: " + sError;
    document.getElementById("publishStatus").innerHTML = sMsg;
    }
    });
    [/javascript]

    Do the above examples make sense? Is the API easy enough to use? How would you establish a connection to the Kwwika service? Would you do anything differently?

    I'd love to get you feedback so please leave your comments below or email me directly using [email protected].