The Azure Management REST API exposes a series of endpoints that allow you to perform various operations against your Azure subscription. This is documented at http://msdn.microsoft.com/en-us/library/windowsazure/ee460799.aspx. You can do many things with the REST API – the majority of Azure management operations can be initiated via this (Note: the Azure PowerShell commandlets wrap calls to the REST API).
To provide a useful example, this article will focus on obtaining the list of Virtual Networks available on a given Azure subscription. In this example, we will call the “Virtual Network” endpoint, as documented at http://msdn.microsoft.com/en-us/library/windowsazure/jj157185.aspx. [Note: this pattern can be applied to any of the REST API endpoints].
As per all management API scenarios, you must first create a management certificate, install it on the machine where you want to run your code from, and upload it to your Azure subscription. A guide for this can be found at http://msdn.microsoft.com/en-us/library/windowsazure/gg551722.aspx.
Once your management certificate is set up on your machine and registered against your Azure subscription, you can call the REST service (in code) by…
- Obtaining the management certificate from the local certificate store (in the code below, this is the personal “my” store).
- Form the HTTP request to call the relevant management service (including the above public certificate in the request headers)
- Call the relevant management service and obtain the response
- Deserialize the response
The code sample below illustrates this. Note this uses two DataContract classes “VirtualNetworkSites” and “VirtualNetworkSite” that match the name of the appropriate elements in the XML response. These DataContract classes were manually created for this example.
Written by Rob Nowik.
Thanks to Christopher Owczarek for his help investigating the Azure REST API.