Mobile Services for Composite C1 : Idea Creation

In this blog post an idea is presented for adding mobile services to C1. Meaning easy exposure of C1 Datatypes by json, Identity and much more.

In this post, I am going to introduce an idea I have been thinking about and the initial hacking. I call it Mobile Services for Composite C1 and it is inspired from Windows Azure Mobile Services.

In composite C1 we already have the part about creating data types and hence tables for them, the bonus here is the freedom of using a data provider of our choice and not only SQL as on Azure. Other than that, the idea is that Composite C1 users can easy select what data types should be exposed from the console and then it is available over the WebAPI stack.

The first step for me was to find out how easy it would be to get a WebAPI up and running within Composite C1. (The focus of this post). Then the second purpose of this post is to invite all of you into the discussion about where this feature should go and what it should include.

Step 1

The first thing I did was to spin up a clean 4.0 site from WebMatrix and opened it in Visual Studio, and then I created a new class library next to it with two classes.

A WebApi Controller. Remember to add the WebAPI client libraries by nuget to use the ApiController

A WebConfiguration class for a WebAPI without the xml formatter. It will then return JSON whenever it returns some data.

The next step was to add the WebAPI WebHost nuget package to the Website Project and in the global.asax add:

Composite.Core.WebApi.WebApiConfig.Register(System.Web.Http.GlobalConfiguration.Configuration);

This means that when the application start it will spin up the WebAPI, and when a route to http://localhost:49396/api/test hits - it finds the controller above and returns hello world back to me.

Step 2

The next step for me was to get it to return some of the data from C1 and while reading up on WebAPI for CRUD i implemented the following classes. (Do not put them on production sites; they also contain methods for editing and deleting data). Future step is to add identity and make such mobile apps can post data back to C1 data types if one want it. I have some ideas about using Azure ACS, Thinktecture Identity Model for securing the WebAPI as it provides me with some good ways of separating out the logic for deciding who will have access to do post/put/delete on data. From the C1 Developer/Editor/User point of view, this will be like on Azure Mobile Servives where you set the security per type/table and operation. (More on that in later post). 

Then by dropping in the following file to the App_Code folder in the website, it get compiled and the API will exposed the Blog posts and Tags with CRUD enabled.

This is just the start and easy part. Now I need some time to reflect over the solution and figure out if this is the way to go. It lets us easy expose data types by dropping in the controllers and the next step could be to get it integrated into the console such one can manage the types that are exposed and the security about who can do post/put/delete/update also.

This also opens the door for creating easy data driven applications in C1 I think. I can create Single Page Application within my C1 Solution and using the API to feed JSON data also. 1 Year ago I was typical using C1 just to have an easy and pretty page on the front to show people vising my company site, and whenever i played around with creating solutions or just learning new stuff, i typical used a MVC4 template. Now I am thinking more about how can I integrate it into my CMS and use it to backend my data and not just html content. This is one example of this. I hope, as how Mobile Services on Azure makes it easy to create a backend for your Windows 8 Store Apps or Phone Apps that Composite C1 can make this easy also and then you get an easy website in the same deal, with all its glory and starter sites. Making it possible for all the new startup ideas to get started without having to pay/find the people for setting those things up.

Let me know if this is something in the right direction.



comments powered by Disqus