jest

by David LaVallee 19. November 2009 22:25

As in surely you jest.

As in JSON + REST (why should this be hard at all?)

As in: "I need web services, but I don't want to construct and deconstruct XML to get data out of my C# based IIS server to my Javascript based client".

So, yesterday I built an ASPX page class that takes a JSON object as its "arg" and returns JSON data with the mime type "text/javascript".

On the server side the JSON gets fully deserialized into a C# System.Collections.Hashtable object. Each JSON type, dictionaries, arrays, strings numbers and bools become their equivalent C# types.

To use Jest you create your ASPX page by subclassing JestPage (instead of Page). Very abbreviated aspx file:

and a pretty simple code behind.

You implement the override method Jest:

The Hashtable is serialized as a JSON response. Excitement should be building at this point, so let's look at a full circuit use example.

Let's keep it simple, Here's my index.html:

The output...

Here's JestPage.cs which is the whole thing:

JustPage.cs (11.16 kb)

Tags:

© 2009 David LaVallée | 206.601.9322 | Resumé