Azure C# SDK

Photo by Brett Sayles from Pexels.com
Photo by Brett Sayles from Pexels.com

I took some time to look at Azure SDK for .Net because I am new to it. In this blog, I share my findings, observations, and sample code.

Azure has REST API to manage its services and resources, and here is the Git repo. We can definitely make HTTPS call to Azure API Server once we understand its specification. Alternatively, we can use the Azure SDK for .Net. (there are many examples and resources over here).

Last week, I have the opportunity to try them out, and my sample code are in a public git repo. Most of the code are in Common folder. For example, to create a resource group, we do

using CSharp_Azure_API.Common;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
...
var subscriptionId = EnvironmentVals.GetSubscription();
var credentials = Authentication.GetCredential();
ResourceGroups oResourceGroups = new ResourceGroups(credentials, subscriptionId);
oResourceGroups.Create(rgName, Region.USWest);

which in turn calls

        public IResourceGroup Create (string name, Region region) {
            if (this.IsExist (name)) {
                return this.azure.ResourceGroups.GetByName (name);
            }
            return this.azure.ResourceGroups
                .Define (name)
                .WithRegion (region)
                .Create ();
        }

from

https://github.com/dennisseah/c-azure-resources/blob/master/Common/ResourceGroups.cs#L29

We also provided similar functions for Virtual Machine, PublicIPAddress, etc. The SDK may not be intuitive because it is generated from Azure REST API Specification (herewith autorest (which is a code generator). From autorest git repo, we see that it is capable of generating code for different languages.

Code generation from autorest
Code generation from autorest

Actually, there are many code generators (like autorest), swagger-client as the most popular one. With code generation, the Azure SDK is always up to date with its REST API.

I have learned a lot after working with the Azure SDK for .Net. Starting with how to create the credential object to different ways to create, delete and list Azure resources. I will add more code to my repo when I have more time in the future. The code should give you an idea on how to use the SDK.






Comments

Popular posts from this blog

Happy New Year, 2024 from DALL-E

Bing Search as tool for OpenAI

OpenAI: Functions Feature in 2023-07-01-preview API version