Using TheLightSwitchToolbox WebApiCommand in the LightSwitch HTML Client

In his original article, Start Web-Api Commanding in 30 Seconds in LightSwitch via nuget TheLightSwitchToolbox, Paul van Bladel used two nuget packages to accomplish this in the Silverlight client.

Make a commanding solution for the HTML client using the same technique is easy as Paul has done most of the work for us.

I am using VisualStudio 2013, but VS2012 wth the LightSwitch update should work as well.

Server Side

As previous, inject the following package into the LightSwitch server project (make sure you are targetting the server project).

Update 11/8/2013: More details on adding the server package

PM> Install-Package TheLightSwitchToolbox.WebApiCommanding.Server

Read Paul’s web-api articles for details on what this package does.

Client Side

Instead of using TheLightSwitchToolbox SilverlightClient we only need to add a couple of lines of code to any screen that requires the ability to call the api.

I have created a HTML project with a table: Person and screen: BrowsePerson To this I added a local string property: CommandReturn at the top of the screen and the method: PeopleCommanding_ItemTap on the Item Tap Action of the list.

VS BrowsePerson Screen Layout

The ItemTap action is very simple and a translation to javascript of the C# in the original Silverlight package.

For this example I made FirstCommand just return what it got in. Again see Paul’s original web-api series for more details.

And with that, it works!

Commanding Complete Screenshot