IgorShare Thoughts and Ideas

Consulting and Training

Archive for April 11th, 2012

Controlling TopShelf via REST interface + Dashboard

Posted by Igor Moochnick on 04/11/2012

My recent update for the TopShelf enables the new Nancy-based REST interface and provides improvements to the current dashboard.

The new REST interface allows you to see what are the currently running services by sending a GET request to the dashboard URL (i.e. http://dasboard_url/services).

As a reply, you’re going to get a JSON block that contains small snippets of information about each seevice and shelf that is running inside the TopShelf process.


The most important piece of the block above is the URL-encoded Name of the service. You can use this name as an ID to control the service’s lifetime via HTTP GET requests, i.e.: start, stop, unload:

  • /service/{name}/start
  • /service/{name}/stop
  • /service/{name}/unload

The latest addition to the control interface is the ability to upload shelves remotely by uploading a ZIP file with all the relevant bits of your service.

You can do the upload via the dashboard by navigating to the ZIP package or by dragging and dropping the shelf archive onto a designated area.

In addition, you can do it programmatically via file upload POST request. This sounds complicated, but, in fact, if you’re using .Net framwork, it may look as simple as this:

using (WebClient client = new WebClient())
     client.UploadFile("http://localhost:8087/service/upload", @"C:\Packages\clock.zip");

All the above functionality can be configured and fine-tuned via the new optional configuration settings that you can put in the TopShelf host configuration file:

	<add key="ServicesLocation" value="Services" />
	<add key="DashboardUri" value="http://localhost:8087" />
	<add key="DashboardUploadsEnable" value="true" />
	<add key="DashboardUploadsPackageFolder" value="Packages" />

Here is a short explanation of the settings:

  • Services – contains a full or relative path of the shelves folder
  • DashboardUri – defines a Uri (ip and port) that the dashboard module (and REST web service) will use to listen to the incoming requests
  • DashboardUploadsEnable – this value controls if the uploads of the shelves are enabled (both through the dashboard and the REST service)
  • DashboardUploadsPackageFolder – defines a temporary location where the ZIP archives of the shelves will be stored before unpacked into the shelves location (defined by the Services setting)

Posted in .NET, REST | 2 Comments »

%d bloggers like this: