Kauri Documentation
 PreviousHomeNext 
3.3 Wire-framing with templatesBook Index3.5 Pulling and displaying data

3.4 Prototype a data-service with JSON

3.4.1 Introduction

Up to now we've been using Kauri to build up the pages that will make up the 'web-site' part of our application. The application interface for the end-user interactions.

Our ambition however is to build a 'web-service' as well. Targeted for machine-machine consumption, this will deliver controlled access to the unformatted data structures (representations in json or XML format).

Still in prototyping mode, Kauri offers a simple mechanism to sketch the messages to be exchanged in these RESTful data-services.  Rather then stepping directly into entity-relation modeling or development of the database back-end we will just draft out some json structures in simple text files.  These function as 'sample' data for simulating the actual persistence features of the eventual production web-service our application needs.  This makes it possible to further enhance our wire-frame-templates making them really data-aware and dynamic: suitable for actual deploy time use.

Even better: this way of working helps define the URI space and the expected exchange messages to and from the persistent service.

We will use this prototyping mode to create blog posts (entries).  On top of this mock service (driven by our json samples) we will complete our templates and interactive pages. Later, we will explain how in production mode, the actual persistence service can be build, and swapped in.

3.4.1.1 Location of the JSON mockup data

The JSON files should be put in the /mockdata directory of the Kauri folder. By using the maven archetype for creation of our application, there is allready a /persons directory present with an example json file 1.json.

Change that into something that better fits our needs:

-- myblog
 |-- conf
 |-- main-module
      |-- src
          |-- main
               |-- kauri
                    |-- mockdata 
                          |-- entry
                               |-- 2010-08-24T14:46:32.json
                               |-- 2010-06-30T12:13:00.json

3.4.1.2 Creation of the JSON data

As hinted above we will create two sample files representing some simple blog posts.  The flexibility of the json notation allows us to easily provide additional fields to these samples as we go along.  For starters we should provide (title, content, summary, key/creation-date)

The names of the files will be used as identifiers for the entities. 

Suggested sample:

{
    "title": "Lily sees the light ... almost!",
    "summary": "This should just grab something like the first 100 characters from the content by default."
    "content": "<p>This is <b>the second day</b> of the very well organized .... (a lot more text)"
}
{
    "title": "A NoSQL Summer: Belgium/Ghent edition",
    "summary": "<p>A NOSQL Summer is a network of local reading groups, that will decipher and discuss 
    "content": "<p>A NOSQL Summer is a network of local reading groups, that will decipher and discuss .... more more more"
}

3.4.1.3 Checking the service

At this point you should restart your running Kauri-instance to let it pick up these new sample files.
To check whether you've put the files at the right place and if the router's configured correctly (this should be the case if you've created your template application with the Maven archetype), try surfing to the following URIs

http://localhost:8888/data/entry/
http://localhost:8888/data/entry/2010-08-24T14:46:32  

The response should contain the contents of the corresponding json files.

You can check what the server actually responded (like HTTP headers and stuff) with a tool like Firebug or the development tools of Chrome.

Finally you can also create new content into this service through standard PUT operations.  To do this from your browser you'll typically need some add-on like the excellent "Poster add-on" for firefox or its "Google Poster" counterpart for Chrome.

You can create or update the entities in the simulated persistence service.

Check out the images for some samples to try out:

 PreviousHomeNext 
3.3 Wire-framing with templates3.5 Pulling and displaying data